From 30f2eae3c7d93488451e6f1d41cf6f446ac08059 Mon Sep 17 00:00:00 2001 From: Ebrahim Date: Fri, 9 Oct 2026 13:41:22 +0330 Subject: [PATCH] [number] Only alter value pointer if parsing was successful Previously it was changing value's pointer even if the parsing was declarad a failure, this fixes it by changing the value only if the parsing was successful. --- src/hb-number.cc | 6 ++++-- src/test-number.cc | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/hb-number.cc b/src/hb-number.cc index b6e7d69c5..bab70e5c7 100644 --- a/src/hb-number.cc +++ b/src/hb-number.cc @@ -45,12 +45,13 @@ _parse_number (const char **pp, const char *end, T *pv, char *pend = p; errno = 0; - *pv = f (p, &pend); + T value = f (p, &pend); if (unlikely (errno || p == pend || /* Check if consumed whole buffer if is requested */ (whole_buffer && pend - p != end - *pp))) return false; + *pv = value; *pp += pend - p; return true; } @@ -76,8 +77,9 @@ bool hb_parse_double (const char **pp, const char *end, double *pv, bool whole_buffer) { const char *pend = end; - *pv = hb_strtod (*pp, &pend); + double value = hb_strtod (*pp, &pend); if (unlikely (*pp == pend)) return false; + *pv = value; *pp = pend; return !whole_buffer || end == pend; } diff --git a/src/test-number.cc b/src/test-number.cc index 088151943..4654ba6d3 100644 --- a/src/test-number.cc +++ b/src/test-number.cc @@ -177,7 +177,7 @@ test_parse_int () int pv = 99; hb_always_assert (!hb_parse_int (&pp, end, &pv)); hb_always_assert (pp == str); - // hb_always_assert (pv == 99); This shouldn't fail but it does with the current implementation + hb_always_assert (pv == 99); } { const char str[] = "+"; @@ -249,7 +249,7 @@ test_parse_int () int pv = 99; hb_always_assert (!hb_parse_int (&pp, end, &pv, true)); hb_always_assert (pp == str); - // hb_always_assert (pv == 99); This shouldn't fail but it does with the current implementation + hb_always_assert (pv == 99); } } @@ -551,7 +551,7 @@ test_parse_uint () /* 'a' isn't a decimal digit; whole parse fails */ hb_always_assert (!hb_parse_uint (&pp, end, &pv, false, 10)); hb_always_assert (pp == str); - // hb_always_assert (pv == 99); this shouldn't fail but it does with the current implementation + hb_always_assert (pv == 99); } { const char str[] = "+"; @@ -815,6 +815,7 @@ test_parse_double (void) const char *end = str + ARRAY_LENGTH (str) - 1; double pv = 99.0; hb_always_assert (!hb_parse_double (&pp, end, &pv)); + hb_always_assert (pv == 99); } { const char str[] = "."; @@ -822,6 +823,7 @@ test_parse_double (void) const char *end = str + ARRAY_LENGTH (str) - 1; double pv = 99.0; hb_always_assert (!hb_parse_double (&pp, end, &pv)); + hb_always_assert (pv == 99); } { const char str[] = "1e-"; @@ -882,6 +884,7 @@ test_parse_double (void) const char *end = str + ARRAY_LENGTH (str) - 1; double pv = 99.0; hb_always_assert (!hb_parse_double (&pp, end, &pv)); + hb_always_assert (pv == 99.0); } { const char str[] = ""; @@ -889,6 +892,7 @@ test_parse_double (void) const char *end = str; double pv = 99.0; hb_always_assert (!hb_parse_double (&pp, end, &pv)); + hb_always_assert (pv == 99.0); } { const char str[] = " \t 123"; @@ -1066,6 +1070,7 @@ test_parse_double (void) const char *end = str + ARRAY_LENGTH (str) - 1; double pv = 99.0; hb_always_assert (!hb_parse_double (&pp, end, &pv)); + hb_always_assert (pv == 99.0); } { const char str[] = "+-1"; @@ -1073,6 +1078,7 @@ test_parse_double (void) const char *end = str + ARRAY_LENGTH (str) - 1; double pv = 99.0; hb_always_assert (!hb_parse_double (&pp, end, &pv)); + hb_always_assert (pv == 99.0); } { const char str[] = "0e5"; @@ -1164,6 +1170,7 @@ test_parse_double (void) const char *end = str + ARRAY_LENGTH (str) - 1; double pv = 99.0; hb_always_assert (!hb_parse_double (&pp, end, &pv)); + hb_always_assert (pv == 99.0); } { const char str[] = "inf"; @@ -1171,6 +1178,7 @@ test_parse_double (void) const char *end = str + ARRAY_LENGTH (str) - 1; double pv = 99.0; hb_always_assert (!hb_parse_double (&pp, end, &pv)); + hb_always_assert (pv == 99.0); } { const char str[] = "1..5"; @@ -1197,6 +1205,7 @@ test_parse_double (void) const char *end = str + ARRAY_LENGTH (str) - 1; double pv = 99.0; hb_always_assert (!hb_parse_double (&pp, end, &pv)); + hb_always_assert (pv == 99.0); } { const char str[] = " abc"; @@ -1205,6 +1214,7 @@ test_parse_double (void) double pv = 99.0; hb_always_assert (!hb_parse_double (&pp, end, &pv)); hb_always_assert (pp == str); + hb_always_assert (pv == 99.0); } {