Skip to content

Commit e026378

Browse files
committed
Change sscanf %s to %Ns
1 parent 5558e1f commit e026378

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,8 +1028,7 @@ String SARA_R5::getIMSI(void)
10281028
String SARA_R5::getCCID(void)
10291029
{
10301030
char *response;
1031-
const int maxTextLen = 21;
1032-
char ccidResponse[maxTextLen] = {0x00}; // E.g. +CCID: 8939107900010087330
1031+
char ccidResponse[21] = {0x00}; // E.g. +CCID: 8939107900010087330
10331032
SARA_R5_error_t err;
10341033

10351034
response = sara_r5_calloc_char(minimumResponseAllocation);
@@ -1043,12 +1042,9 @@ String SARA_R5::getCCID(void)
10431042
{
10441043
searchPtr += strlen("\r\n+CCID:"); // Move searchPtr to first character - probably a space
10451044
while (*searchPtr == ' ') searchPtr++; // skip spaces
1046-
if (strlen(searchPtr) < maxTextLen) // Check we have enough space to hold the text
1045+
if (sscanf(searchPtr, "%20s", ccidResponse) != 1)
10471046
{
1048-
if (sscanf(searchPtr, "%s", ccidResponse) != 1)
1049-
{
1050-
ccidResponse[0] = 0;
1051-
}
1047+
ccidResponse[0] = 0;
10521048
}
10531049
}
10541050
}
@@ -1059,8 +1055,7 @@ String SARA_R5::getCCID(void)
10591055
String SARA_R5::getSubscriberNo(void)
10601056
{
10611057
char *response;
1062-
const int maxTextLen = 128;
1063-
char idResponse[maxTextLen] = {0x00}; // E.g. +CNUM: "ABCD . AAA","123456789012",129
1058+
char idResponse[128] = {0x00}; // E.g. +CNUM: "ABCD . AAA","123456789012",129
10641059
SARA_R5_error_t err;
10651060

10661061
response = sara_r5_calloc_char(minimumResponseAllocation);
@@ -1074,12 +1069,9 @@ String SARA_R5::getSubscriberNo(void)
10741069
{
10751070
searchPtr += strlen("\r\n+CNUM:"); // Move searchPtr to first character - probably a space
10761071
while (*searchPtr == ' ') searchPtr++; // skip spaces
1077-
if (strlen(searchPtr) < maxTextLen) // Check we have enough space to hold the text
1072+
if (sscanf(searchPtr, "%127s", idResponse) != 1)
10781073
{
1079-
if (sscanf(searchPtr, "%s", idResponse) != 1)
1080-
{
1081-
idResponse[0] = 0;
1082-
}
1074+
idResponse[0] = 0;
10831075
}
10841076
}
10851077
}

0 commit comments

Comments
 (0)