mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-24 00:11:14 +01:00
[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.
This commit is contained in:
1 parent
1622d7cb09
commit
30f2eae3c7
2 files changed
+17
-5
No files matched your search
+4
-2
@@ -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;
|
||||
}
|
||||
|
||||
+13
-3
@@ -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);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user