From 3661eb6105a33a763736d8dc4a2cd95c01aa4332 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Tue, 3 Sep 2019 19:43:14 +0430 Subject: [PATCH] Don't check null terminaion of source in hb_codepoint_parse This isn't what intended originally, just checking if consumed all the buffer is enough. --- src/hb-algs.hh | 4 ++-- src/test-number.cc | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 66433a2b7..9caf5e93e 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -902,8 +902,8 @@ hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *o const char *end = p + len; if (unlikely (!hb_parse_uint (&p, end, &v, base))) return false; - /* Pain because we don't know whether s is nul-terminated. */ - if (unlikely (p != end && *p)) return false; + /* Check if parser consumed all of the buffer */ + if (unlikely (p != end)) return false; *out = v; return true; diff --git a/src/test-number.cc b/src/test-number.cc index 8ec66eecf..0a33f7f29 100644 --- a/src/test-number.cc +++ b/src/test-number.cc @@ -40,6 +40,7 @@ main (int argc, char **argv) assert (pv == 123); assert (pp - str == 3); assert (end - pp == 0); + assert (!*end); } { @@ -52,6 +53,20 @@ main (int argc, char **argv) assert (pv == 123); assert (pp - str == 3); assert (end - pp == 0); + assert (!*end); + } + + { + const char str[] = "12F"; + const char *pp = str; + const char *end = str + 3; + + unsigned int pv; + assert (hb_parse_uint (&pp, end, &pv, 16)); + assert (pv == 0x12F); + assert (pp - str == 3); + assert (end - pp == 0); + assert (!*end); } { @@ -64,6 +79,7 @@ main (int argc, char **argv) assert (pv == -123); assert (pp - str == 4); assert (end - pp == 0); + assert (!*end); } { @@ -77,6 +93,7 @@ main (int argc, char **argv) assert (pv == 123); assert (pp - str == 3); assert (end - pp == 1); + assert (!*end); } { @@ -89,7 +106,20 @@ main (int argc, char **argv) assert (hb_parse_uint (&pp, end, &pv)); assert (pv == 123); assert (pp - str == 3); - assert (end - pp == 2); /* Similar to what hb_codepoint_parse needs */ + assert (end - pp == 2); + } + + { + const char str[] = "123V"; + const char *pp = str; + assert (ARRAY_LENGTH (str) == 5); + const char *end = str + ARRAY_LENGTH (str); + + unsigned int pv; + assert (hb_parse_uint (&pp, end, &pv)); + assert (pv == 123); + assert (pp - str == 3); + assert (end - pp == 2); } {