Skip to content

Commit

Permalink
Bug fix in string to int parse code
Browse files Browse the repository at this point in the history
If the string to parse is "0" (or "00", "000", "0000...", etc.) then after all
the "leading zeroes" have been skipped, cur and end will point to the same
location, causing the function to return false.

To fix, check if we have reached end-of-string after skipping the leading
zeroes. If we have reached the end of the string and this is not an empty
string (i.e. count > 0) then the parsed integer has value 0 and we can return
true.
  • Loading branch information
adrianherrera committed Oct 1, 2015
1 parent 6e44f6b commit 8d06611
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/scripting/toplevel/Integer.cpp
Expand Up @@ -247,8 +247,19 @@ bool Integer::fromStringFlashCompatible(const char* cur, int64_t& ret, int radix
//Skip leading zeroes
if (radix == 0)
{
int count=0;
while(*cur=='0')
{
cur++;
count++;
}

//The string consisted of all zeroes
if(count>0 && *cur=='\0')
{
ret = 0;
return true;
}
}

errno=0;
Expand Down

0 comments on commit 8d06611

Please sign in to comment.