mirror of
https://github.com/janet-lang/janet
synced 2025-01-10 23:50:26 +00:00
Update strtod.c to be less accepting of some badly formed numbers.
This commit is contained in:
parent
b31791200b
commit
7e63427208
@ -149,6 +149,7 @@ static struct DstScanRes dst_scan_impl(
|
|||||||
|
|
||||||
/* Initialize flags */
|
/* Initialize flags */
|
||||||
int seenadigit = 0;
|
int seenadigit = 0;
|
||||||
|
int gotradix = 0;
|
||||||
|
|
||||||
/* Initialize result */
|
/* Initialize result */
|
||||||
res.mant = 0;
|
res.mant = 0;
|
||||||
@ -197,15 +198,19 @@ static struct DstScanRes dst_scan_impl(
|
|||||||
} else if (res.base == 10 && (*str == 'E' || *str == 'e')) {
|
} else if (res.base == 10 && (*str == 'E' || *str == 'e')) {
|
||||||
res.foundexp = 1;
|
res.foundexp = 1;
|
||||||
break;
|
break;
|
||||||
} else if (*str == 'x' || *str == 'X') {
|
} else if (!gotradix && (*str == 'x' || *str == 'X')) {
|
||||||
if (res.seenpoint || res.mant > 0) goto error;
|
if (res.seenpoint || res.mant > 0) goto error;
|
||||||
res.base = 16;
|
res.base = 16;
|
||||||
res.mant = 0;
|
res.mant = 0;
|
||||||
} else if (*str == 'r' || *str == 'R') {
|
seenadigit = 0;
|
||||||
|
gotradix = 1;
|
||||||
|
} else if (!gotradix && (*str == 'r' || *str == 'R')) {
|
||||||
if (res.seenpoint) goto error;
|
if (res.seenpoint) goto error;
|
||||||
if (res.mant < 2 || res.mant > 36) goto error;
|
if (res.mant < 2 || res.mant > 36) goto error;
|
||||||
res.base = res.mant;
|
res.base = res.mant;
|
||||||
res.mant = 0;
|
res.mant = 0;
|
||||||
|
seenadigit = 0;
|
||||||
|
gotradix = 1;
|
||||||
} else if (*str == '_') {
|
} else if (*str == '_') {
|
||||||
;
|
;
|
||||||
/* underscores are ignored - can be used for separator */
|
/* underscores are ignored - can be used for separator */
|
||||||
@ -242,6 +247,10 @@ static struct DstScanRes dst_scan_impl(
|
|||||||
while (str < end && *str == '0') str++;
|
while (str < end && *str == '0') str++;
|
||||||
while (str < end && ee < (INT32_MAX / 40)) {
|
while (str < end && ee < (INT32_MAX / 40)) {
|
||||||
int digit = digit_lookup[*str & 0x7F];
|
int digit = digit_lookup[*str & 0x7F];
|
||||||
|
if (*str == '_') {
|
||||||
|
str++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (*str > 127 || digit >= res.base) goto error;
|
if (*str > 127 || digit >= res.base) goto error;
|
||||||
ee = res.base * ee + digit;
|
ee = res.base * ee + digit;
|
||||||
str++;
|
str++;
|
||||||
|
@ -169,7 +169,6 @@ static uint8_t checkescape(uint8_t c) {
|
|||||||
case 'f': return '\f';
|
case 'f': return '\f';
|
||||||
case 'e': return 27;
|
case 'e': return 27;
|
||||||
case '"': return '"';
|
case '"': return '"';
|
||||||
case '\'': return '\'';
|
|
||||||
case '\\': return '\\';
|
case '\\': return '\\';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,4 +67,10 @@
|
|||||||
(assert (= nil (get roottab :childprop)), "table get 2")
|
(assert (= nil (get roottab :childprop)), "table get 2")
|
||||||
(assert (= 456 (get childtab :childprop)), "proto no effect")
|
(assert (= 456 (get childtab :childprop)), "proto no effect")
|
||||||
|
|
||||||
|
# Long strings
|
||||||
|
|
||||||
|
(assert (= "hello, world" \==\hello, world\==\), "simple long string")
|
||||||
|
(assert (= "hello, \"world\"" \\hello, "world"\\), "long string with embedded quotes")
|
||||||
|
(assert (= "hello, \\\\\\ \"world\"" \=\hello, \\\ "world"\=\), "long string with embedded quotes and backslashes")
|
||||||
|
|
||||||
(end-suite)
|
(end-suite)
|
||||||
|
Loading…
Reference in New Issue
Block a user