hb-font: Fix a potentially undefined use of memcmp() (#413)
authorPhilip Withnall <philip@tecnocode.co.uk>
Wed, 8 Feb 2017 21:56:57 +0000 (21:56 +0000)
committerBehdad Esfahbod <behdad@behdad.org>
Wed, 8 Feb 2017 21:56:57 +0000 (13:56 -0800)
While it’s fine to call memcmp(x, 0, 0) in practice, the C99 standard
explicitly says that this is not allowed: even if the length is zero,
the pointer arguments must be valid.

http://stackoverflow.com/a/16363034

Coverity ID: 141178

Signed-off-by: Philip Withnall <withnall@endlessm.com>
src/hb-font.cc

index a08766f5b62c1c3d99a31f300ee937cc3ce3519c..e900bd3f65aedd47a7a38448395a938809ae1ab1 100644 (file)
@@ -1596,7 +1596,8 @@ _hb_font_adopt_var_coords_normalized (hb_font_t *font,
                                      unsigned int coords_length)
 {
   if (font->num_coords == coords_length &&
-      0 == memcmp (font->coords, coords, coords_length * sizeof (coords[0])))
+      (coords_length == 0 ||
+       0 == memcmp (font->coords, coords, coords_length * sizeof (coords[0]))))
   {
     free (coords);
     return;