Skip to content

Fix valgrind defects from cellular #9457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ TEST_F(TestATHandler, test_ATHandler_list)
EXPECT_TRUE(at1->close() == NSAPI_ERROR_OK);
EXPECT_TRUE(at2->get_ref_count() == 1);
EXPECT_TRUE(at2->close() == NSAPI_ERROR_OK);
EXPECT_TRUE(at1->close() == NSAPI_ERROR_PARAMETER);

ATHandler::set_at_timeout_list(1000, false);
ATHandler::set_debug_list(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ TEST_F(Testutil, prefer_ipv6)

TEST_F(Testutil, separate_ip_addresses)
{
char *s = (char *)malloc(128);

char s[128] = {'\0'};
char ip[64] = {0};
char subnet[64] = {0};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ TEST_F(TestCellularDevice, test_get_context_list)
CellularContext *ctx = dev->create_context();
EXPECT_TRUE(dev->get_context_list());
delete dev;
dev = NULL;

dev = new myCellularDevice(&fh1);
EXPECT_TRUE(dev);
EXPECT_FALSE(dev->get_context_list());
delete dev;
}

TEST_F(TestCellularDevice, test_stop)
Expand Down
4 changes: 2 additions & 2 deletions UNITTESTS/stubs/ATHandler_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ int ATHandler_stub::int_count = kRead_int_table_size;
bool ATHandler_stub::process_oob_urc = false;

int ATHandler_stub::read_string_index = kRead_string_table_size;
const char *ATHandler_stub::read_string_table[kRead_string_table_size];
const char *ATHandler_stub::read_string_table[kRead_string_table_size] = {'\0'};
int ATHandler_stub::resp_stop_success_count = kResp_stop_count_default;
int ATHandler_stub::urc_amount = 0;
mbed::Callback<void()> ATHandler_stub::callback[kATHandler_urc_table_max_size];
char *ATHandler_stub::urc_string_table[kATHandler_urc_table_max_size];
char *ATHandler_stub::urc_string_table[kATHandler_urc_table_max_size] = {'\0'};

ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const char *output_delimiter, uint16_t send_delay) :
_nextATHandler(0),
Expand Down
19 changes: 14 additions & 5 deletions UNITTESTS/stubs/AT_CellularDevice_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const int DEFAULT_AT_TIMEOUT = 1000;

using namespace mbed;


int AT_CellularDevice_stub::failure_count = 0;
nsapi_error_t AT_CellularDevice_stub::nsapi_error_value = 0;
int AT_CellularDevice_stub::init_module_failure_count = 0;
Expand All @@ -33,8 +32,7 @@ int AT_CellularDevice_stub::get_sim_failure_count = 0;
bool AT_CellularDevice_stub::pin_needed = false;

AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0),
_information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT),
_modem_debug_on(false)
_information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), _modem_debug_on(false)
{
}

Expand Down Expand Up @@ -77,7 +75,13 @@ void delete_context(CellularContext *context)

CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh)
{
return new AT_CellularNetwork(*ATHandler::get_instance(fh, _queue, _default_timeout, "\r", get_send_delay(), _modem_debug_on));
_network = new AT_CellularNetwork(*ATHandler::get_instance(fh,
_queue,
_default_timeout,
"\r",
get_send_delay(),
_modem_debug_on));
return _network;
}

CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh)
Expand All @@ -92,6 +96,9 @@ CellularInformation *AT_CellularDevice::open_information(FileHandle *fh)

void AT_CellularDevice::close_network()
{
delete _network;

_network = NULL;
}

void AT_CellularDevice::close_sms()
Expand Down Expand Up @@ -123,7 +130,9 @@ void AT_CellularDevice::delete_context(CellularContext *context)

AT_CellularNetwork *AT_CellularDevice::open_network_impl(ATHandler &at)
{
return new AT_CellularNetwork(at);
_network = new AT_CellularNetwork(at);

return _network;
}

AT_CellularSMS *AT_CellularDevice::open_sms_impl(ATHandler &at)
Expand Down
9 changes: 4 additions & 5 deletions features/cellular/framework/AT/ATHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,11 @@ int32_t ATHandler::read_int()
}

char buff[BUFF_SIZE];
char *first_no_digit;

if (read_string(buff, (size_t)sizeof(buff)) == 0) {
if (read_string(buff, sizeof(buff)) == 0) {
return -1;
}

return std::strtol(buff, &first_no_digit, 10);
return std::strtol(buff, NULL, 10);
}

void ATHandler::set_delimiter(char delimiter)
Expand Down Expand Up @@ -1211,8 +1209,9 @@ void ATHandler::debug_print(const char *p, int len)
#if MBED_CONF_MBED_TRACE_ENABLE
mbed_cellular_trace::mutex_wait();
#endif
char c;
for (ssize_t i = 0; i < len; i++) {
char c = *p++;
c = *p++;
if (!isprint(c)) {
if (c == '\r') {
debug("\n");
Expand Down
1 change: 1 addition & 0 deletions tools/test/travis-ci/doxy-spellchecker/ignore.en.pws
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
personal_ws-1.1 en 1600 utf-8
_code_
unconfigured
mbed
rtos
malloc
Expand Down