[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] trunk r115366: Minor integer overflow fixes.
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] trunk r115366: Minor integer overflow fixes. |
Date: |
Tue, 03 Dec 2013 21:37:51 +0000 |
User-agent: |
Bazaar (2.6b2) |
------------------------------------------------------------
revno: 115366
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/16033
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Tue 2013-12-03 13:37:41 -0800
message:
Minor integer overflow fixes.
* 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.
modified:
src/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1438
src/window.c window.c-20091113204419-o5vbwnq5f7feedwu-231
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog 2013-12-03 07:45:54 +0000
+++ b/src/ChangeLog 2013-12-03 21:37:41 +0000
@@ -1,3 +1,11 @@
+2013-12-03 Paul Eggert <address@hidden>
+
+ 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 <address@hidden>
* window.c (Fset_window_new_pixel): Don't choke at negative
=== modified file 'src/window.c'
--- a/src/window.c 2013-12-03 07:45:54 +0000
+++ b/src/window.c 2013-12-03 21:37:41 +0000
@@ -3646,10 +3646,8 @@
(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))
@@ -3729,18 +3727,20 @@
/* 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))
@@ -3751,18 +3751,20 @@
/* 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. */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] trunk r115366: Minor integer overflow fixes.,
Paul Eggert <=