]> git.eshelyaron.com Git - emacs.git/commitdiff
Beware large stack growth in pgtk_menu_show
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 27 Jan 2025 06:15:49 +0000 (22:15 -0800)
committerEshel Yaron <me@eshelyaron.com>
Thu, 30 Jan 2025 18:06:31 +0000 (19:06 +0100)
* src/pgtkmenu.c (pgtk_menu_show): USE_SAFE_ALLOCA instead of alloca.
Problem found with --enable-gcc-warnings.

(cherry picked from commit 6ff06ff738ead96d7b4cb59eda15a1c72e2b5776)

src/pgtkmenu.c
src/xmenu.c

index a2e09b6cb58df23f17d364921ecb90bd80aab6ad..54e1c3739cf62e25f33f49d312c209fdd4ae2f75 100644 (file)
@@ -596,14 +596,10 @@ pgtk_menu_show (struct frame *f, int x, int y, int menuflags,
 {
   int i;
   widget_value *wv, *save_wv = 0, *first_wv = 0, *prev_wv = 0;
-  widget_value **submenu_stack
-    = alloca (menu_items_used * sizeof *submenu_stack);
-  Lisp_Object *subprefix_stack
-    = alloca (menu_items_used * sizeof *subprefix_stack);
+  widget_value **submenu_stack;
+  Lisp_Object *subprefix_stack;
   int submenu_depth = 0;
 
-  specpdl_ref specpdl_count = SPECPDL_INDEX ();
-
   eassert (FRAME_PGTK_P (f));
 
   *error_name = NULL;
@@ -614,6 +610,11 @@ pgtk_menu_show (struct frame *f, int x, int y, int menuflags,
       return Qnil;
     }
 
+  USE_SAFE_ALLOCA;
+  SAFE_NALLOCA (submenu_stack, 1, menu_items_used);
+  SAFE_NALLOCA (subprefix_stack, 1, menu_items_used);
+  specpdl_ref specpdl_count = SPECPDL_INDEX ();
+
   block_input ();
 
   /* Create a tree of widget_value objects
@@ -830,6 +831,7 @@ pgtk_menu_show (struct frame *f, int x, int y, int menuflags,
                          entry = Fcons (subprefix_stack[j], entry);
                    }
                  unblock_input ();
+                 SAFE_FREE ();
                  return entry;
                }
              i += MENU_ITEMS_ITEM_LENGTH;
@@ -844,6 +846,7 @@ pgtk_menu_show (struct frame *f, int x, int y, int menuflags,
     }
 
   unblock_input ();
+  SAFE_FREE ();
   return Qnil;
 }
 
index ce5cdbcfc0b080a1d61e9b6886519c54c4fc1cec..f95c50b183306ba1f672bc917022af1707e13fe8 100644 (file)
@@ -1898,14 +1898,10 @@ x_menu_show (struct frame *f, int x, int y, int menuflags,
   widget_value **submenu_stack;
   Lisp_Object *subprefix_stack;
   int submenu_depth = 0;
-  specpdl_ref specpdl_count;
-
   USE_SAFE_ALLOCA;
-
   SAFE_NALLOCA (submenu_stack, 1, menu_items_used);
   SAFE_NALLOCA (subprefix_stack, 1, menu_items_used);
-
-  specpdl_count = SPECPDL_INDEX ();
+  specpdl_ref specpdl_count = SPECPDL_INDEX ();
 
   eassert (FRAME_X_P (f));