From 31c4236d9643063e518289b28c3e17cedd8401e0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 24 May 2018 13:38:46 -0700 Subject: [PATCH] Underflow protection in hb_vector_t --- src/hb-private.hh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/hb-private.hh b/src/hb-private.hh index 45f699040..0d1cc0ef3 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -685,8 +685,9 @@ struct hb_vector_t return true; } - inline bool resize (unsigned int size) + inline bool resize (int size_) { + unsigned int size = size_ < 0 ? 0u : (unsigned int) size_; if (!alloc (size)) return false; @@ -696,6 +697,7 @@ struct hb_vector_t inline void pop (void) { + if (!len) return; len--; } @@ -709,10 +711,11 @@ struct hb_vector_t len--; } - inline void shrink (unsigned int l) + inline void shrink (int size_) { - if (l < len) - len = l; + unsigned int size = size_ < 0 ? 0u : (unsigned int) size_; + if (size < len) + len = size; } template