+2013-12-03 Paul Eggert <eggert@cs.ucla.edu>
+
+ Minor integer overflow fixes (Bug#16033).
+ * window.c (Fset_window_new_pixel): Don't let new_pixel go negative.
+ This improves on the previous fix to this function.
+ (window_resize_check): When summing up pixel counts, don't rely on
+ undefined behavior if the sum overflows.
+
2013-12-03 Martin Rudalics <rudalics@gmx.at>
* window.c (Fset_window_new_pixel): Don't choke at negative
(Lisp_Object window, Lisp_Object size, Lisp_Object add)
{
struct window *w = decode_valid_window (window);
- EMACS_INT size_min = (max (INT_MIN, MOST_NEGATIVE_FIXNUM)
- + (NILP (add) ? 0 : XINT (w->new_pixel)));
- EMACS_INT size_max = (min (INT_MAX, MOST_POSITIVE_FIXNUM)
- - (NILP (add) ? 0 : XINT (w->new_pixel)));
+ EMACS_INT size_min = NILP (add) ? 0 : - XINT (w->new_pixel);
+ EMACS_INT size_max = size_min + min (INT_MAX, MOST_POSITIVE_FIXNUM);
CHECK_RANGED_INTEGER (size, size_min, size_max);
if (NILP (add))
/* The sum of the heights of the child windows of W must equal
W's height. */
{
- int sum_of_pixels = 0;
+ int remaining_pixels = XINT (w->new_pixel);
while (c)
{
if (!window_resize_check (c, horflag))
return 0;
- sum_of_pixels = sum_of_pixels + XINT (c->new_pixel);
+ remaining_pixels -= XINT (c->new_pixel);
+ if (remaining_pixels < 0)
+ return 0;
c = NILP (c->next) ? 0 : XWINDOW (c->next);
}
- return (sum_of_pixels == XINT (w->new_pixel));
+ return remaining_pixels == 0;
}
}
else if (WINDOW_HORIZONTAL_COMBINATION_P (w))
/* The sum of the widths of the child windows of W must equal W's
width. */
{
- int sum_of_pixels = 0;
+ int remaining_pixels = XINT (w->new_pixel);
while (c)
{
if (!window_resize_check (c, horflag))
return 0;
- sum_of_pixels = sum_of_pixels + XINT (c->new_pixel);
+ remaining_pixels -= XINT (c->new_pixel);
+ if (remaining_pixels < 0)
+ return 0;
c = NILP (c->next) ? 0 : XWINDOW (c->next);
}
- return (sum_of_pixels == XINT (w->new_pixel));
+ return remaining_pixels == 0;
}
else
/* All child windows of W must have the same height as W. */