Skip to content

Commit 7c469b9

Browse files
committed
Revert "tom_modem: fix pdu decoding issue #124"
This reverts commit 474a8f1.
1 parent 1143f4b commit 7c469b9

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

application/tom_modem/src/extlib/pdu.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,7 @@ int pdu_decode(const unsigned char* buffer, int buffer_length,
404404
case 2:
405405
{
406406
// UCS2
407-
if (output_sms_text_length < sms_text_size) {
408-
memcpy(output_sms_text, buffer + sms_start + 1, output_sms_text_length);
409-
output_sms_text[output_sms_text_length] = '\0';
410-
} else {
411-
memcpy(output_sms_text, buffer + sms_start + 1, sms_text_size - 1);
412-
output_sms_text[sms_text_size - 1] = '\0';
413-
}
407+
memcpy(output_sms_text, buffer + sms_start + 1, output_sms_text_length);
414408
break;
415409
}
416410
default:

application/tom_modem/src/operations.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,11 @@ int sms_read(PROFILE_T *profile, void *transport_ptr)
114114
dbg_msg("No PDU found for line: %s", line);
115115
pdu = strtok(NULL, "\n");
116116
}
117-
sms->sms_pdu = (char *)malloc(strlen(pdu) + 1);
117+
sms->sms_pdu = (char *)malloc(strlen(pdu));
118118
sms->sender = (char *)malloc(PHONE_NUMBER_SIZE);
119119
sms->sms_text = (char *)malloc(SMS_TEXT_SIZE);
120120
sms->sms_index = get_sms_index(line);
121121
memcpy(sms->sms_pdu, pdu, strlen(pdu));
122-
sms->sms_pdu[strlen(pdu)] = '\0';
123-
printf("sms->sms_pdu = %s", sms->sms_pdu);
124122
int sms_len = decode_pdu(sms);
125123
if (sms_len > 0)
126124
{
@@ -236,12 +234,11 @@ int sms_read_unread(PROFILE_T *profile, void *transport_ptr)
236234
dbg_msg("No PDU found for line: %s", line);
237235
pdu = strtok(NULL, "\n");
238236
}
239-
sms->sms_pdu = (char *)malloc(strlen(pdu) + 1);
237+
sms->sms_pdu = (char *)malloc(strlen(pdu));
240238
sms->sender = (char *)malloc(PHONE_NUMBER_SIZE);
241239
sms->sms_text = (char *)malloc(SMS_TEXT_SIZE);
242240
sms->sms_index = get_sms_index(line);
243241
memcpy(sms->sms_pdu, pdu, strlen(pdu));
244-
sms->sms_pdu[strlen(pdu)] = '\0';
245242
int sms_len = decode_pdu(sms);
246243
if (sms_len > 0)
247244
{

application/tom_modem/src/utils.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ int decode_pdu(SMS_T *sms)
117117
// UCS2
118118
sms->type = SMS_CHARSET_UCS2;
119119
int offset = 0;
120-
int text_len = strlen(sms_text);
121-
for (int i = skip_bytes; i < text_len - 1; i += 2)
120+
for (int i = skip_bytes; i < SMS_TEXT_SIZE; i += 2)
122121
{
123122
int ucs2_char = 0x000000FF & sms_text[i + 1];
124123
ucs2_char |= (0x0000FF00 & (sms_text[i] << 8));
@@ -127,14 +126,16 @@ int decode_pdu(SMS_T *sms)
127126
int j;
128127
for (j = 0; j < len; j++)
129128
{
130-
sms->sms_text[offset] = utf8_char[j];
129+
sprintf(sms->sms_text + offset, "%c", utf8_char[j]);
131130
if (utf8_char[j] != '\0')
132131
{
133132
offset++;
134133
}
134+
135135
}
136136
}
137-
sms->sms_text[offset] = '\0';
137+
offset++;
138+
sprintf(sms->sms_text + offset, "%c", '\0');
138139
break;
139140
}
140141
default:

0 commit comments

Comments
 (0)