Minor integer overflow fixes.
[bpt/emacs.git] / src / window.c
index e62fdad..e277041 100644 (file)
@@ -1212,7 +1212,7 @@ coordinates_in_window (register struct window *w, int x, int y)
     return ON_NOTHING;
 
   /* On vertical window divider (which prevails horizontal
-     dividers) ?  */
+     dividers)?  */
   if (!WINDOW_RIGHTMOST_P (w)
       && WINDOW_RIGHT_DIVIDER_WIDTH (w)
       && x >= right_x - WINDOW_RIGHT_DIVIDER_WIDTH (w)
@@ -1285,8 +1285,8 @@ coordinates_in_window (register struct window *w, int x, int y)
      terminals, the vertical line's x coordinate is right_x.  */
   else if (!w->pseudo_window_p
           && !WINDOW_RIGHTMOST_P (w)
-          /* Why check ux if we are not the rightmost window ?  Also
-             shouldn't a pseudo window always be rightmost ?  */
+          /* Why check ux if we are not the rightmost window?  Also
+             shouldn't a pseudo window always be rightmost?  */
           && x > right_x - ux)
     return ON_VERTICAL_BORDER;
 
@@ -3646,8 +3646,10 @@ Note: This function does not operate on any child windows of WINDOW.  */)
   (Lisp_Object window, Lisp_Object size, Lisp_Object add)
 {
   struct window *w = decode_valid_window (window);
+  EMACS_INT size_max = (min (INT_MAX, MOST_POSITIVE_FIXNUM)
+                       - (NILP (add) ? 0 : XINT (w->new_pixel)));
 
-  CHECK_NUMBER (size);
+  CHECK_RANGED_INTEGER (size, 0, size_max);
   if (NILP (add))
     wset_new_pixel (w, size);
   else
@@ -4556,12 +4558,14 @@ grow_mini_window (struct window *w, int delta, bool pixelwise)
 
          if (pixelwise)
            {
-             pixel_height = -XINT (height);
+             pixel_height = min (-XINT (height), INT_MAX - w->pixel_height);
              line_height = pixel_height / FRAME_LINE_HEIGHT (f);
            }
          else
            {
-             line_height = -XINT (height);
+             line_height = min (-XINT (height),
+                                ((INT_MAX - w->pixel_height)
+                                 / FRAME_LINE_HEIGHT (f)));
              pixel_height = line_height * FRAME_LINE_HEIGHT (f);
            }
 
@@ -5844,12 +5848,12 @@ struct save_window_data
        From `frame-cols' down, the fields are ignored by the GC.  */
     /* We should be able to do without the following two.  */
     int frame_cols, frame_lines;
-    /* These two should get eventually replaced by their pixelized
+    /* These two should get eventually replaced by their pixel
        counterparts.  */
     int frame_menu_bar_lines, frame_tool_bar_lines;
     int frame_text_width, frame_text_height;
-    /* These are currently unused.  We need them as soon as we pixelize
-       them.  */
+    /* These are currently unused.  We need them as soon as we convert
+       to pixels.  */
     int frame_menu_bar_height, frame_tool_bar_height;
   };