From 790771b18cec8904df45088de109b948402827ac Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 3 Apr 2011 00:05:43 -0700 Subject: [PATCH] * font.c (font_score): Avoid potential overflow in diff calculation. --- src/ChangeLog | 1 + src/font.c | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 02cdc170f5c..49ba5ef3462 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,6 +1,7 @@ 2011-04-03 Paul Eggert * font.c (font_find_for_lface, Ffont_get_glyphs): Remove unused vars. + (font_score): Avoid potential overflow in diff calculation. * fns.c (substring_both): Remove var that is set but not used. (sxhash): Redo loop for clarity and to avoid wraparound warning. diff --git a/src/font.c b/src/font.c index 02262e1cb81..5d67c0032e6 100644 --- a/src/font.c +++ b/src/font.c @@ -2076,12 +2076,11 @@ font_score (Lisp_Object entity, Lisp_Object *spec_prop) for (i = FONT_WEIGHT_INDEX; i <= FONT_WIDTH_INDEX; i++) if (! NILP (spec_prop[i]) && ! EQ (AREF (entity, i), spec_prop[i])) { - int diff = (XINT (AREF (entity, i)) >> 8) - (XINT (spec_prop[i]) >> 8); - + EMACS_INT diff = ((XINT (AREF (entity, i)) >> 8) + - (XINT (spec_prop[i]) >> 8)); if (diff < 0) diff = - diff; - if (diff > 0) - score |= min (diff, 127) << sort_shift_bits[i]; + score |= min (diff, 127) << sort_shift_bits[i]; } /* Score the size. Maximum difference is 127. */ -- 2.39.5