Skip to content

Commit a5a2036

Browse files
authored
Merge pull request #11224 from AnttiKauppila/Coverity_fixes
Coverity issues fixed
2 parents e3bfcbc + 84063bf commit a5a2036

File tree

9 files changed

+46
-15
lines changed

9 files changed

+46
-15
lines changed

UNITTESTS/stubs/CellularUtil_stub.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ int hex_str_to_char_str(const char *str, uint16_t len, char *buf)
110110
return 1;
111111
}
112112

113+
void hex_to_char(const char *hex, char &buf)
114+
{
115+
buf = CellularUtil_stub::char_ptr[CellularUtil_stub::char_pos++];
116+
}
117+
113118
void uint_to_binary_str(uint32_t num, char *str, int str_size, int bit_cnt)
114119
{
115120

components/wifi/esp8266-driver/ESP8266/ESP8266.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ ESP8266::ESP8266(PinName tx, PinName rx, bool debug, PinName rts, PinName cts)
4949
_parser(&_serial),
5050
_packets(0),
5151
_packets_end(&_packets),
52+
_sock_active_id(-1),
5253
_heap_usage(0),
5354
_connect_error(0),
5455
_disconnect(false),
5556
_fail(false),
5657
_sock_already(false),
5758
_closed(false),
59+
_error(false),
5860
_busy(false),
5961
_reset_check(_rmutex),
6062
_reset_done(false),
@@ -97,6 +99,10 @@ ESP8266::ESP8266(PinName tx, PinName rx, bool debug, PinName rts, PinName cts)
9799
_sock_i[i].tcp_data_avbl = 0;
98100
_sock_i[i].tcp_data_rcvd = 0;
99101
}
102+
103+
_scan_r.res = NULL;
104+
_scan_r.limit = 0;
105+
_scan_r.cnt = 0;
100106
}
101107

102108
bool ESP8266::at_available()
@@ -328,8 +334,8 @@ nsapi_error_t ESP8266::connect(const char *ap, const char *passPhrase)
328334
_smutex.lock();
329335
set_timeout(ESP8266_CONNECT_TIMEOUT);
330336

331-
_parser.send("AT+CWJAP_CUR=\"%s\",\"%s\"", ap, passPhrase);
332-
if (!_parser.recv("OK\n")) {
337+
bool res = _parser.send("AT+CWJAP_CUR=\"%s\",\"%s\"", ap, passPhrase);
338+
if (!res || !_parser.recv("OK\n")) {
333339
if (_fail) {
334340
if (_connect_error == 1) {
335341
ret = NSAPI_ERROR_CONNECTION_TIMEOUT;

components/wifi/esp8266-driver/ESP8266Interface.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName r
9494
_if_blocking(true),
9595
_if_connected(_cmutex),
9696
_initialized(false),
97+
_connect_retval(NSAPI_ERROR_OK),
9798
_conn_stat(NSAPI_STATUS_DISCONNECTED),
9899
_conn_stat_cb(NULL),
99100
_global_event_queue(mbed_event_queue()), // Needs to be set before attaching event() to SIGIO
@@ -298,7 +299,7 @@ int ESP8266Interface::set_credentials(const char *ssid, const char *pass, nsapi_
298299
if (pass_length >= ESP8266_PASSPHRASE_MIN_LENGTH
299300
&& pass_length <= ESP8266_PASSPHRASE_MAX_LENGTH) {
300301
memset(ap_pass, 0, sizeof(ap_pass));
301-
strncpy(ap_pass, pass, sizeof(ap_pass));
302+
strncpy(ap_pass, pass, ESP8266_PASSPHRASE_MAX_LENGTH);
302303
} else {
303304
return NSAPI_ERROR_PARAMETER;
304305
}

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ ssize_t ATHandler::read_hex_string(char *buf, size_t size)
698698
} else {
699699
hexbuf[read_idx % 2] = c;
700700
if (read_idx % 2 == 1) {
701-
hex_str_to_char_str(hexbuf, 2, buf + buf_idx);
701+
hex_to_char(hexbuf, *(buf + buf_idx));
702702
}
703703
}
704704
}
@@ -923,7 +923,7 @@ void ATHandler::resp(const char *prefix, bool check_urc)
923923

924924
while (!get_last_error()) {
925925

926-
match(CRLF, CRLF_LENGTH);
926+
(void)match(CRLF, CRLF_LENGTH);
927927

928928
if (match(OK, OK_LENGTH)) {
929929
set_scope(RespType);
@@ -1281,6 +1281,7 @@ void ATHandler::cmd_start_stop(const char *cmd, const char *cmd_chr, const char
12811281

12821282
nsapi_error_t ATHandler::at_cmd_str(const char *cmd, const char *cmd_chr, char *resp_buf, size_t buf_size, const char *format, ...)
12831283
{
1284+
MBED_ASSERT(strlen(cmd) < BUFF_SIZE);
12841285
lock();
12851286

12861287
handle_start(cmd, cmd_chr);

features/cellular/framework/AT/AT_CellularSMS.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void AT_CellularSMS::cmt_urc()
188188
{
189189
tr_debug("CMT_URC called");
190190
//+CMT: <oa>,[<alpha>],<scts>[,<tooa>,<fo>,<pid>,<dcs>,<sca>,<tosca>,<length>]<CR><LF><data>
191-
_at.consume_to_stop_tag();
191+
(void)_at.consume_to_stop_tag();
192192
// call user defined callback function
193193
if (_cb) {
194194
_cb();
@@ -1205,27 +1205,27 @@ uint16_t AT_CellularSMS::unpack_7_bit_gsm_to_str(const char *str, int len, char
12051205
char tmp1;
12061206

12071207
if (padding_bits) {
1208-
hex_str_to_char_str(str, 2, &tmp);
1208+
hex_to_char(str, tmp);
12091209
buf[decodedCount] = gsm_to_ascii[(tmp >> padding_bits) & 0x7F];
12101210
strCount++;
12111211
decodedCount++;
12121212
}
12131213

12141214
while (strCount < len) {
12151215
shift = (strCount - padding_bits) % 7;
1216-
hex_str_to_char_str(str + strCount * 2, 2, &tmp);
1216+
hex_to_char(str + strCount * 2, tmp);
12171217
if (shift == 0) {
12181218
buf[decodedCount] = gsm_to_ascii[tmp & 0x7F];
12191219
} else if (shift == 6) {
1220-
hex_str_to_char_str(str + (strCount - 1) * 2, 2, &tmp1);
1220+
hex_to_char(str + (strCount - 1) * 2, tmp1);
12211221
buf[decodedCount] = gsm_to_ascii[(((tmp1 >> 2)) | (tmp << 6)) & 0x7F];
12221222
if (decodedCount + 1 < msg_len) {
1223-
hex_str_to_char_str(str + strCount * 2, 2, &tmp);
1223+
hex_to_char(str + strCount * 2, tmp);
12241224
decodedCount++;
12251225
buf[decodedCount] = gsm_to_ascii[(tmp >> 1) & 0x7F];
12261226
}
12271227
} else {
1228-
hex_str_to_char_str(str + (strCount - 1) * 2, 2, &tmp1);
1228+
hex_to_char(str + (strCount - 1) * 2, tmp1);
12291229
buf[decodedCount] = gsm_to_ascii[(((tmp1 >> (8 - shift))) | ((tmp << shift))) & 0x7F];
12301230
}
12311231

features/cellular/framework/common/CellularUtil.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,22 @@ int hex_str_to_char_str(const char *str, uint16_t len, char *buf)
271271
{
272272
int strcount = 0;
273273
for (int i = 0; i + 1 < len; i += 2) {
274-
int upper = hex_str_to_int(str + i, 1);
275-
int lower = hex_str_to_int(str + i + 1, 1);
276-
buf[strcount] = ((upper << 4) & 0xF0) | (lower & 0x0F);
274+
char tmp;
275+
hex_to_char(str + i, tmp);
276+
buf[strcount] = tmp;
277277
strcount++;
278278
}
279279

280280
return strcount;
281281
}
282282

283+
void hex_to_char(const char *hex, char &buf)
284+
{
285+
int upper = hex_str_to_int(hex, 1);
286+
int lower = hex_str_to_int(hex + 1, 1);
287+
buf = ((upper << 4) & 0xF0) | (lower & 0x0F);
288+
}
289+
283290
void uint_to_binary_str(uint32_t num, char *str, int str_size, int bit_cnt)
284291
{
285292
if (!str || str_size < bit_cnt) {

features/cellular/framework/common/CellularUtil.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ int hex_str_to_int(const char *hex_string, int hex_string_length);
105105
*/
106106
int hex_str_to_char_str(const char *str, uint16_t len, char *buf);
107107

108+
/** Converts the given hex string to char
109+
*
110+
* @param str A hex value that is converted to char
111+
* @param buf A char variable where result conversion is stored
112+
*/
113+
void hex_to_char(const char *hex, char &buf);
114+
108115
/** Converts the given uint to binary string. Fills the given str starting from [0] with the number of bits defined by bit_cnt
109116
* For example uint_to_binary_string(9, str, 10) would fill str "0000001001"
110117
* For example uint_to_binary_string(9, str, 3) would fill str "001"

features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularStack.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ nsapi_size_or_error_t QUECTEL_M26_CellularStack::socket_sendto_impl(CellularSock
478478
_at.resp_start("+QISACK:");
479479
sent_len_before = _at.read_int();
480480
sent_acked = _at.read_int();
481+
(void)sent_acked;
481482
sent_nacked = _at.read_int();
482483
_at.resp_stop();
483484

features/lwipstack/LWIPStack.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ void LWIP::tcpip_init_irq(void *eh)
162162
LWIP::LWIP()
163163
{
164164
default_interface = NULL;
165+
tcpip_thread_id = NULL;
165166

166167
// Seed lwip random
167168
lwip_seed_random();
@@ -208,7 +209,9 @@ nsapi_error_t LWIP::add_dns_server(const SocketAddress &address, const char *int
208209
const ip_addr_t *ip_addr_move;
209210
ip_addr_t ip_addr;
210211

211-
convert_mbed_addr_to_lwip(&ip_addr, &addr);
212+
if (!convert_mbed_addr_to_lwip(&ip_addr, &addr)) {
213+
return NSAPI_ERROR_PARAMETER;
214+
}
212215

213216
if (ip_addr_isany(&ip_addr)) {
214217
return NSAPI_ERROR_NO_ADDRESS;

0 commit comments

Comments
 (0)