diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 96cc1573e..66433a2b7 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -900,10 +900,10 @@ hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *o unsigned int v; const char *p = s; const char *end = p + len; - if (!hb_parse_uint (&p, p + len, &v, base)) - return false; + if (unlikely (!hb_parse_uint (&p, end, &v, base))) return false; - if (end != p && *p) return false; + /* Pain because we don't know whether s is nul-terminated. */ + if (unlikely (p != end && *p)) return false; *out = v; return true; diff --git a/src/hb-buffer-serialize.cc b/src/hb-buffer-serialize.cc index a6e3bb81a..5f65d314f 100644 --- a/src/hb-buffer-serialize.cc +++ b/src/hb-buffer-serialize.cc @@ -384,12 +384,10 @@ parse_int (const char *pp, const char *end, int32_t *pv) { int v; const char *p = pp; - if (!hb_parse_int (&p, end, &v)) - return false; + if (unlikely (!hb_parse_int (&p, end, &v))) return false; /* Check if parser consumed all of the buffer */ - if (p != end) - return false; + if (unlikely (p != end)) return false; *pv = v; return true; diff --git a/src/hb-common.cc b/src/hb-common.cc index 690c96f11..6ad834635 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -721,11 +721,10 @@ parse_char (const char **pp, const char *end, char c) static bool parse_uint (const char **pp, const char *end, unsigned int *pv) { - /* Intentionally use strtol inside instead of strtoul, such that - * -1 turns into "big number"... */ + /* Intentionally use hb_parse_int inside instead of hb_parse_uint, + * such that -1 turns into "big number"... */ int v; - if (!hb_parse_int (pp, end, &v)) - return false; + if (unlikely (!hb_parse_int (pp, end, &v))) return false; *pv = v; return true; @@ -734,11 +733,10 @@ parse_uint (const char **pp, const char *end, unsigned int *pv) static bool parse_uint32 (const char **pp, const char *end, uint32_t *pv) { - /* Intentionally use strtol inside instead of strtoul, such that - * -1 turns into "big number"... */ + /* Intentionally use hb_parse_int inside instead of hb_parse_uint, + * such that -1 turns into "big number"... */ int v; - if (!hb_parse_int (pp, end, &v)) - return false; + if (unlikely (!hb_parse_int (pp, end, &v))) return false; *pv = v; return true; diff --git a/src/hb-number.cc b/src/hb-number.cc index 4a86ddddd..d5acd2b11 100644 --- a/src/hb-number.cc +++ b/src/hb-number.cc @@ -32,7 +32,7 @@ #endif template -static inline bool +static bool _parse_number (const char **pp, const char *end, T *pv, Func f) { char buf[32]; @@ -42,13 +42,11 @@ _parse_number (const char **pp, const char *end, T *pv, Func f) char *p = buf; char *pend = p; - T v; errno = 0; - v = f (p, &pend); + *pv = f (p, &pend); if (unlikely (errno || p == pend)) return false; - *pv = v; *pp += pend - p; return true; }