From 929f07dbfc8b8c40771d27a502f6e5842c1c1e90 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 15:38:48 -0500 Subject: [PATCH] Fix hb_bytes_t.cmp() Ouch! --- src/hb-dsalgs.hh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index ffa438704..e98566e75 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -530,10 +530,12 @@ struct hb_bytes_t inline int cmp (const hb_bytes_t &a) const { - if (len != a.len) - return (int) a.len - (int) len; + if (!len) return 0; /* glibc's memcmp() args are declared nonnull. Meh. */ - return memcmp (a.arrayZ, arrayZ, len); + int r = memcmp (a.arrayZ, arrayZ, len); + if (r) return r; + + return a.len < len ? -1 : a.len > len ? +1 : 0; } static inline int cmp (const void *pa, const void *pb) {