Ignore leading and trailing whitespace when parsing floats
This commit is contained in:
parent
c865e0dc78
commit
6b134d11ff
@ -2821,15 +2821,16 @@ KrkValue krk_parse_float(const char * s, size_t l) {
|
||||
|
||||
union Float { double d; uint64_t i; };
|
||||
|
||||
while (c < l && (s[c] == ' ' || s[c] == '\t' || s[c] == '\n' || s[c] == '\r')) c++;
|
||||
|
||||
/* Collect a leading sign. */
|
||||
if (s[c] == '-') {
|
||||
sign = -1;
|
||||
c++;
|
||||
ps = 1;
|
||||
} else if (s[c] == '+') {
|
||||
c++;
|
||||
ps = 1;
|
||||
}
|
||||
ps = c;
|
||||
|
||||
/* Case-insensitive check for stringy floats: nan, inf */
|
||||
if (c + 3 == l) {
|
||||
@ -2867,6 +2868,8 @@ KrkValue krk_parse_float(const char * s, size_t l) {
|
||||
ee = c;
|
||||
}
|
||||
|
||||
while (c < l && (s[c] == ' ' || s[c] == '\t' || s[c] == '\n' || s[c] == '\r')) c++;
|
||||
|
||||
/* If we're not at the end here, we have invalid characters. */
|
||||
if (c != l) return krk_runtimeError(vm.exceptions->valueError, "invalid literal for float");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user