Minor integer overflow fixes.
[bpt/emacs.git] / src / window.c
index e73c50f..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
@@ -3784,102 +3786,6 @@ window_resize_check (struct window *w, bool horflag)
                                    : FRAME_LINE_HEIGHT (f)));
 }
 
-static int
-window_resize_total_check (struct window *w, int horflag)
-{
-  struct frame *f = XFRAME (w->frame);
-  struct window *c;
-
-  if (WINDOW_VERTICAL_COMBINATION_P (w))
-    /* W is a vertical combination.  */
-    {
-      c = XWINDOW (w->contents);
-      if (horflag)
-       /* All child windows of W must have the same width as W.  */
-       {
-         while (c)
-           {
-             if (XINT (c->new_pixel) != XINT (w->new_pixel)
-/**              || XINT (c->new_total != XINT (w->new_total)) **/
-                 || !window_resize_check (c, horflag))
-               return 0;
-
-             c = NILP (c->next) ? 0 : XWINDOW (c->next);
-           }
-
-         return 1;
-       }
-      else
-       /* The sum of the heights of the child windows of W must equal
-          W's height.  */
-       {
-         int sum_of_pixels = 0, sum_of_totals = 0;
-
-         while (c)
-           {
-             if (!window_resize_check (c, horflag))
-               return 0;
-
-             sum_of_pixels = sum_of_pixels + XINT (c->new_pixel);
-/**          sum_of_totals = sum_of_totals + XINT (c->new_total); **/
-             c = NILP (c->next) ? 0 : XWINDOW (c->next);
-           }
-
-         return (sum_of_pixels == XINT (w->new_pixel)
-/**              && sum_of_totals == XINT (w->new_total) **/
-                 );
-       }
-    }
-  else if (WINDOW_HORIZONTAL_COMBINATION_P (w))
-    /* W is a horizontal combination.  */
-    {
-      c = XWINDOW (w->contents);
-      if (horflag)
-       /* The sum of the widths of the child windows of W must equal W's
-          width.  */
-       {
-         int sum_of_pixels = 0, sum_of_totals = 0;
-
-         while (c)
-           {
-             if (!window_resize_check (c, horflag))
-               return 0;
-
-             sum_of_pixels = sum_of_pixels + XINT (c->new_pixel);
-             sum_of_totals = sum_of_totals + XINT (c->new_total);
-             c = NILP (c->next) ? 0 : XWINDOW (c->next);
-           }
-
-         return (sum_of_pixels == XINT (w->new_pixel)
-/**              && sum_of_totals == XINT (w->new_total) **/
-                 );
-       }
-      else
-       /* All child windows of W must have the same height as W.  */
-       {
-         while (c)
-           {
-             if (XINT (c->new_pixel) != XINT (w->new_pixel)
-/**              || XINT (c->new_total) != XINT (w->new_total) **/
-                 || !window_resize_check (c, horflag))
-               return 0;
-
-             c = NILP (c->next) ? 0 : XWINDOW (c->next);
-           }
-
-         return 1;
-       }
-    }
-  else
-    /* A leaf window.  Make sure it's not too small.  The following
-       hardcodes the values of `window-safe-min-width' (2) and
-       `window-safe-min-height' (1) which are defined in window.el.  */
-    return (XINT (w->new_pixel) >= (horflag
-                                   ? (2 * FRAME_COLUMN_WIDTH (f))
-                                   : FRAME_LINE_HEIGHT (f))
-/**        && XINT (w->new_total) >= (horflag ? 2 : 1) **/
-           );
-}
 
 /* Set w->pixel_height (w->pixel_height if HORIZONTAL is non-zero) to
    w->new_pixel for window W and recursively all child windows of W.
@@ -4129,7 +4035,7 @@ resize_frame_windows (struct frame *f, int size, bool horflag, bool pixelwise)
                                   ? FRAME_COLUMN_WIDTH (f)
                                   : FRAME_LINE_HEIGHT (f));
     }
-  else    
+  else
     {
       new_size= (horflag
                 ? size
@@ -4652,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);
            }
 
@@ -4687,7 +4595,7 @@ shrink_mini_window (struct window *w, bool pixelwise)
 
   eassert (MINI_WINDOW_P (w));
 
-  height = pixelwise ? w->pixel_height : w->total_lines; 
+  height = pixelwise ? w->pixel_height : w->total_lines;
   unit = pixelwise ? FRAME_LINE_HEIGHT (f) : 1;
   if (height > unit)
     {
@@ -5940,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;
   };
 
@@ -6078,10 +5986,10 @@ the return value is nil.  Otherwise the value is t.  */)
         back.  We keep track of the prevailing height in these variables.  */
       int previous_frame_text_height = FRAME_TEXT_HEIGHT (f);
       int previous_frame_text_width =  FRAME_TEXT_WIDTH  (f);
-      int previous_frame_menu_bar_height = FRAME_MENU_BAR_HEIGHT (f);
-      int previous_frame_tool_bar_height = FRAME_TOOL_BAR_HEIGHT (f);
-      int previous_frame_lines = FRAME_LINES (f);
-      int previous_frame_cols =  FRAME_COLS  (f);
+      /* int previous_frame_menu_bar_height = FRAME_MENU_BAR_HEIGHT (f); */
+      /* int previous_frame_tool_bar_height = FRAME_TOOL_BAR_HEIGHT (f); */
+      /* int previous_frame_lines = FRAME_LINES (f); */
+      /* int previous_frame_cols =  FRAME_COLS  (f); */
       int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f);
       int previous_frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f);
 
@@ -6353,7 +6261,7 @@ the return value is nil.  Otherwise the value is t.  */)
       /* This `select_window' calls record_buffer which calls Fdelq which
         invokes QUIT, so we do it here at the end rather than earlier,
         to minimize the risk of interrupting the Fset_window_configuration
-        in an inconsistent state (e.g. before frame-focus redirection is 
+        in an inconsistent state (e.g. before frame-focus redirection is
         canceled).  */
       select_window (data->current_window, Qnil, 1);
       BVAR (XBUFFER (XWINDOW (selected_window)->contents),