Skip to content

Commit d621185

Browse files
committed
Fix issue #274
Don't strtod if value contains non alpha/number characters.
1 parent cdc43fe commit d621185

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Firmware/RTK_Surveyor/NVM.ino

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,22 +456,30 @@ bool parseLine(char* str, Settings *settings)
456456
}
457457
else
458458
{
459+
//if (strcmp(settingName, "ntripServer_CasterHost") == 0) //Debug
460+
// Serial.printf("Found problem spot raw: %s\n\r", str);
461+
459462
//Assume the value is a string such as 8d8a48b. The leading number causes skipSpace to fail.
460463
//If settingValue has a mix of letters and numbers, just convert to string
461464
sprintf(settingValue, "%s", str);
462465

463466
//Check if string is mixed
464467
bool isNumber = false;
465468
bool isLetter = false;
469+
bool isOther = false;
466470
for (int x = 0 ; x < strlen(settingValue) ; x++)
467471
{
468-
if (isAlpha(settingValue[x])) isLetter = true;
469472
if (isDigit(settingValue[x])) isNumber = true;
473+
else if (isAlpha(settingValue[x])) isLetter = true;
474+
else isOther = true;
470475
}
471476

472-
if (isLetter && isNumber)
477+
if ( (isLetter && isNumber) || isOther) //See issue: https://github.com/sparkfun/SparkFun_RTK_Firmware/issues/274
473478
{
474479
//It's a mix. Skip strtod.
480+
481+
//if (strcmp(settingName, "ntripServer_CasterHost") == 0) //Debug
482+
// Serial.printf("Skipping strtod - settingValue: %s\n\r", settingValue);
475483
}
476484
else
477485
{
@@ -927,12 +935,12 @@ bool parseLine(char* str, Settings *settings)
927935
{
928936
uint8_t macAddress[6];
929937
uint8_t macByte = 0;
930-
938+
931939
char* token = strtok(settingValue, ","); //Break string up on ,
932-
while(token != NULL && macByte < sizeof(macAddress))
940+
while (token != NULL && macByte < sizeof(macAddress))
933941
{
934942
settings->espnowPeers[x][macByte++] = (uint8_t)strtol(token, NULL, 16);
935-
token = strtok(NULL, ",");
943+
token = strtok(NULL, ",");
936944
}
937945

938946
knownSetting = true;

0 commit comments

Comments
 (0)