From b8402ad3881d6a53e50810f3e488cd50e5e5192a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 22 Dec 2023 21:46:01 +0100 Subject: [PATCH] Fix js_strtod with large integers Ref: https://github.com/bellard/quickjs/commit/a96f44074650a1fa064645f245e9f38c14450b70 --- quickjs.c | 8 ++++++-- tests/test_language.js | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/quickjs.c b/quickjs.c index 54c0608..199f282 100644 --- a/quickjs.c +++ b/quickjs.c @@ -9987,12 +9987,13 @@ static inline int to_digit(int c) } /* XXX: remove */ -static double js_strtod(const char *p, int radix, BOOL is_float) +static double js_strtod(const char *str, int radix, BOOL is_float) { double d; int c; if (!is_float || radix != 10) { + const char *p = str; uint64_t n_max, n; int int_exp, is_neg; @@ -10019,6 +10020,8 @@ static double js_strtod(const char *p, int radix, BOOL is_float) if (n <= n_max) { n = n * radix + c; } else { + if (radix == 10) + goto strtod_case; int_exp++; } p++; @@ -10030,7 +10033,8 @@ static double js_strtod(const char *p, int radix, BOOL is_float) if (is_neg) d = -d; } else { - d = strtod(p, NULL); + strtod_case: + d = strtod(str, NULL); } return d; } diff --git a/tests/test_language.js b/tests/test_language.js index 746fa0e..b6ce4e4 100644 --- a/tests/test_language.js +++ b/tests/test_language.js @@ -120,6 +120,7 @@ function test_cvt() assert((Infinity >>> 0) === 0); assert(((-Infinity) >>> 0) === 0); assert(((4294967296 * 3 - 4) >>> 0) === (4294967296 - 4)); + assert((19686109595169230000).toString() === "19686109595169230000"); } function test_eq()