Fixed coverity warnings for AT_CellularSMS.cpp

pull/6496/head
Teppo Järvelin 2018-03-20 12:53:15 +02:00
parent 89843246ac
commit f6be35c0f2
1 changed files with 12 additions and 28 deletions

View File

@ -352,8 +352,6 @@ char* AT_CellularSMS::create_pdu(const char* phone_number, const char* message,
pdu[x++] = '0'; pdu[x++] = '0';
} }
// possible to use 16 bit identifier, can't be defined yet from outside
bool use_16_bit_identifier = false;
uint8_t udhlen = 0; uint8_t udhlen = 0;
// Length can be update after we have created PDU, store position for later use. // Length can be update after we have created PDU, store position for later use.
int lengthPos = x; int lengthPos = x;
@ -363,34 +361,17 @@ char* AT_CellularSMS::create_pdu(const char* phone_number, const char* message,
if (msg_parts > 1) { // concatenated, must use UDH if (msg_parts > 1) { // concatenated, must use UDH
// user data header length in chars // user data header length in chars
pdu[x++] = '0'; pdu[x++] = '0';
if (use_16_bit_identifier) { udhlen = 6; // udh length in chars (5) + udhl length in chars
udhlen = 7; // udh length in chars (6) + udhl length in chars pdu[x++] = '5';
pdu[x++] = '6';
} else {
udhlen = 6; // udh length in chars (5) + udhl length in chars
pdu[x++] = '5';
}
// Information element identifier // Information element identifier
pdu[x++] = '0'; pdu[x++] = '0';
if (use_16_bit_identifier) { pdu[x++] = '0';
pdu[x++] = '8';
} else {
pdu[x++] = '0';
}
// Information element data length // Information element data length
pdu[x++] = '0'; pdu[x++] = '0';
if (use_16_bit_identifier) { pdu[x++] = '3';
pdu[x++] = '4';
} else {
pdu[x++] = '3';
}
// A reference number (must be the same for all parts of the same larger messages) // A reference number (must be the same for all parts of the same larger messages)
int_to_hex_str(_sms_message_ref_number&0xFF, pdu+x); int_to_hex_str(_sms_message_ref_number&0xFF, pdu+x);
x +=2; x +=2;
if (use_16_bit_identifier) {
int_to_hex_str((_sms_message_ref_number>>16)&0xFF, pdu+x);
x +=2;
}
// How many parts does this message have? // How many parts does this message have?
int_to_hex_str(msg_parts, pdu+x); int_to_hex_str(msg_parts, pdu+x);
x +=2; x +=2;
@ -678,13 +659,13 @@ nsapi_size_or_error_t AT_CellularSMS::read_sms_from_index(int msg_index, char* b
nsapi_size_or_error_t AT_CellularSMS::read_sms(sms_info_t* sms, char* buf, char* phone_num, char* time_stamp) nsapi_size_or_error_t AT_CellularSMS::read_sms(sms_info_t* sms, char* buf, char* phone_num, char* time_stamp)
{ {
// +CMGR: <stat>,[<alpha>],<length><CR><LF><pdu> // +CMGR: <stat>,[<alpha>],<length><CR><LF><pdu>
int index = -1; int index;
if (sms->parts == sms->parts_added) { if (sms->parts == sms->parts_added) {
char *pdu; // we need a temp buffer as payload is hexencoded ---> can't use buf as it might be enough for message but not hexenconded pdu. char *pdu; // we need a temp buffer as payload is hexencoded ---> can't use buf as it might be enough for message but not hexenconded pdu.
int status = -1; int status;
int msg_len = 0; int msg_len;
index = 0; index = 0;
int pduSize = 0; int pduSize;
for (int i = 0; i < sms->parts; i++) { for (int i = 0; i < sms->parts; i++) {
wait_ms(_sim_wait_time); wait_ms(_sim_wait_time);
@ -1212,13 +1193,16 @@ uint16_t AT_CellularSMS::pack_7_bit_gsm_and_hex(const char* str, uint16_t len, c
uint8_t shift; uint8_t shift;
char tmp; char tmp;
if (len == 0) {
return 0;
}
// convert to 7bit gsm first // convert to 7bit gsm first
char* gsm_str = (char*)malloc(len); char* gsm_str = (char*)malloc(len);
if (!gsm_str) { if (!gsm_str) {
return 0; return 0;
} }
for (uint16_t y = 0; y < len; y++) { for (uint16_t y = 0; y < len; y++) {
for (int x=0; x < GSM_TO_ASCII_TABLE_SIZE; x++) { for (int x=0; x < GSM_TO_ASCII_TABLE_SIZE; x++) {
if (gsm_to_ascii[x] == str[y]) { if (gsm_to_ascii[x] == str[y]) {
gsm_str[y] = x; gsm_str[y] = x;
} }