]> git.eshelyaron.com Git - emacs.git/commitdiff
* 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 02cdc170f5c3f9d26cd371e8e1d8979667419459..49ba5ef34622bc222cdfbc732b61ac3171b77179 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 02262e1cb81fc8bae5aa3d9e0cafda99345e4f12..5d67c0032e60d4f41e87b35f1bf359ad985a80f9 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.  */