Skip to content

Commit

Permalink
Merge pull request #96 from simonhyde/flexible-input
Browse files Browse the repository at this point in the history
Be more forgiving of input with leading zeros
  • Loading branch information
cpainchaud authored Nov 9, 2023
2 parents 14b9023 + 25f159a commit 1773b1d
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions RFLink/4_Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,19 @@ boolean retrieve_decimalNumber(unsigned long &value, byte maxDigits, const char*
if ((prefix != NULL) && (strncasecmp(ptr, prefix, strlen(prefix)) == 0))
ptr += strlen(prefix);

if (strlen(ptr) > maxDigits)
//Make this length check more forgiving by dropping leading 0s
size_t len = strlen(ptr);

while(len > 1 && ptr[0] == '0')
{
ptr++;
len--;
}

if (len > maxDigits)
return false;

for (byte i = 0; i < strlen(ptr); i++)
for (byte i = 0; i < len; i++)
if (!isdigit(ptr[i]))
return false;

Expand All @@ -430,10 +439,19 @@ boolean retrieve_hexNumber(unsigned long &value, byte maxNibbles, const char* pr
if ((prefix != NULL) && (strncasecmp(ptr, prefix, strlen(prefix)) == 0))
ptr += strlen(prefix);

if (strlen(ptr) > maxNibbles)
//Make this length check more forgiving by dropping leading 0s
size_t len = strlen(ptr);

while(len > 1 && ptr[0] == '0')
{
ptr++;
len--;
}

if (len > maxNibbles)
return false;

for (byte i = 0; i < strlen(ptr); i++)
for (byte i = 0; i < len; i++)
if (!isxdigit(ptr[i]))
return false;

Expand Down

0 comments on commit 1773b1d

Please sign in to comment.