* font.c (font_score): Avoid potential overflow in diff calculation.
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 3 Apr 2011 07:05:43 +0000 (00:05 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 3 Apr 2011 07:05:43 +0000 (00:05 -0700)
src/ChangeLog
src/font.c

index 02cdc17..49ba5ef 100644 (file)
@@ -1,6 +1,7 @@
 2011-04-03  Paul Eggert  <eggert@cs.ucla.edu>
 
        * 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.
index 02262e1..5d67c00 100644 (file)
@@ -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.  */