From 670fec231d31bf7417de590efd3485f337a7330f Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Thu, 10 Oct 2019 09:21:08 +0330 Subject: [PATCH] Minor, add a zero length tolerant memset, hb_memset --- src/hb-algs.hh | 10 +++++++++- src/hb-buffer.cc | 3 +-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index c57481bfe..042e1c20d 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -588,10 +588,18 @@ hb_memcmp (const void *a, const void *b, unsigned int len) /* It's illegal to pass NULL to memcmp(), even if len is zero. * So, wrap it. * https://sourceware.org/bugzilla/show_bug.cgi?id=23878 */ - if (!len) return 0; + if (unlikely (!len)) return 0; return memcmp (a, b, len); } +static inline void * +hb_memset (void *s, int c, unsigned int n) +{ + /* It's illegal to pass NULL to memset(), even if n is zero. */ + if (unlikely (!n)) return 0; + return memset (s, c, n); +} + static inline bool hb_unsigned_mul_overflows (unsigned int count, unsigned int size) { diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index bb7f3c7c1..40ac55c1c 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -324,8 +324,7 @@ hb_buffer_t::clear_positions () out_len = 0; out_info = info; - if (likely (len)) - memset (pos, 0, sizeof (pos[0]) * len); + hb_memset (pos, 0, sizeof (pos[0]) * len); } void