* src/comp.c (declare_imported_func, emit_simple_limple_call)
(declare_lex_function, compile_function):
* src/emacs-module.c (funcall_module):
* src/fns.c (Fstring_distance):
* src/font.c (font_sort_entities):
* src/haikumenu.c (digest_menu_items, haiku_menu_show):
* src/pgtkselect.c (Fpgtk_register_dnd_targets):
* src/xfns.c (Fx_begin_drag):
* src/xmenu.c (x_menu_show):
* src/xterm.c (x_dnd_compute_toplevels, handle_one_xevent)
(x_term_init):
Prefer SAFE_NALLOCA to doing size multiplication by hand, to catch
unlikely integer overflows.
* src/comp.c (emit_simple_limple_call): Fix bug where
SAFE_FREE was called too early, leading to unlikely
use of freed storage.
* src/xterm.c (handle_one_xevent): Remove side effects
from SAFE_ALLOCA args, as the args are evaluated twice.
(cherry picked from commit
101ec1430128a0b1d9e7d54cbd9c0add8f446f25)
}
else if (!types)
{
- types = SAFE_ALLOCA (nargs * sizeof (* types));
+ SAFE_NALLOCA (types, 1, nargs);
for (ptrdiff_t i = 0; i < nargs; i++)
types[i] = comp.lisp_obj_type;
}
emit_simple_limple_call (Lisp_Object args, gcc_jit_type *ret_type, bool direct)
{
USE_SAFE_ALLOCA;
- int i = 0;
Lisp_Object callee = FIRST (args);
args = XCDR (args);
- ptrdiff_t nargs = list_length (args);
- gcc_jit_rvalue **gcc_args = SAFE_ALLOCA (nargs * sizeof (*gcc_args));
+ ptrdiff_t i = 0, nargs = list_length (args);
+ gcc_jit_rvalue **gcc_args;
+ SAFE_NALLOCA (gcc_args, 1, nargs);
FOR_EACH_TAIL (args)
gcc_args[i++] = emit_mvar_rval (XCAR (args));
+ gcc_jit_rvalue *res = emit_call (callee, ret_type, nargs, gcc_args, direct);
SAFE_FREE ();
- return emit_call (callee, ret_type, nargs, gcc_args, direct);
+ return res;
}
static gcc_jit_rvalue *
{
EMACS_INT max_args = XFIXNUM (CALL1I (comp-args-max, args));
eassert (max_args < INT_MAX);
- gcc_jit_type **type = SAFE_ALLOCA (max_args * sizeof (*type));
+ gcc_jit_type **type;
+ SAFE_NALLOCA (type, 1, max_args);
for (ptrdiff_t i = 0; i < max_args; i++)
type[i] = comp.lisp_obj_type;
- gcc_jit_param **params = SAFE_ALLOCA (max_args * sizeof (*params));
+ gcc_jit_param **params;
+ SAFE_NALLOCA (params, 1, max_args);
for (int i = 0; i < max_args; ++i)
params[i] = gcc_jit_context_new_param (comp.ctxt,
NULL,
comp.func_relocs_ptr_type,
"freloc");
- comp.frame = SAFE_ALLOCA (comp.frame_size * sizeof (*comp.frame));
+ SAFE_NALLOCA (comp.frame, 1, comp.frame_size);
if (comp.func_has_non_local || !comp.func_speed)
{
/* FIXME: See bug#42360. */
record_unwind_protect_module (SPECPDL_MODULE_ENVIRONMENT, env);
USE_SAFE_ALLOCA;
- emacs_value *args = nargs > 0 ? SAFE_ALLOCA (nargs * sizeof *args) : NULL;
+ emacs_value *args;
+ /* FIXME: Is this (nargs <= 0) test needed? Either omit it and call
+ SAFE_NALLOCA unconditionally, or fix this comment to explain why
+ the test is needed. */
+ if (nargs <= 0)
+ args = NULL;
+ else
+ SAFE_NALLOCA (args, 1, nargs);
+
for (ptrdiff_t i = 0; i < nargs; ++i)
{
args[i] = lisp_to_value (env, arglist[i]);
ptrdiff_t x, y, lastdiag, olddiag;
USE_SAFE_ALLOCA;
- ptrdiff_t *column = SAFE_ALLOCA ((len1 + 1) * sizeof (ptrdiff_t));
+ ptrdiff_t *column;
+ SAFE_NALLOCA (column, 1, len1 + 1);
for (y = 0; y <= len1; y++)
column[y] = y;
maxlen = ASIZE (vec);
}
- data = SAFE_ALLOCA (maxlen * sizeof *data);
+ SAFE_NALLOCA (data, 1, maxlen);
best_score = 0xFFFFFFFF;
best_entity = Qnil;
bool is_menu_bar)
{
void **menus, **panes;
- ssize_t menu_len;
- ssize_t pane_len;
int i, menu_depth;
void *menu, *window, *view;
Lisp_Object pane_name, prefix;
USE_SAFE_ALLOCA;
- menu_len = (menu_items_used + 1 - start) * sizeof *menus;
- pane_len = (menu_items_used + 1 - start) * sizeof *panes;
+ int menu_len = menu_items_used - start + 1;
+ int pane_len = menu_items_used - start + 1;
menu = first_menu;
i = start;
menu_depth = 0;
- menus = SAFE_ALLOCA (menu_len);
- panes = SAFE_ALLOCA (pane_len);
- memset (menus, 0, menu_len);
- memset (panes, 0, pane_len);
+ SAFE_NALLOCA (menus, 1, menu_len);
+ SAFE_NALLOCA (panes, 1, pane_len);
+ memset (menus, 0, menu_len * sizeof *menus);
menus[0] = first_menu;
+ memset (panes, 0, pane_len * sizeof *panes);
window = NULL;
view = NULL;
view = FRAME_HAIKU_VIEW (f);
i = 0;
submenu_depth = 0;
- subprefix_stack
- = SAFE_ALLOCA (menu_items_used * sizeof (Lisp_Object));
+ SAFE_NALLOCA (subprefix_stack, 1, menu_items_used);
eassert (FRAME_HAIKU_P (f));
CHECK_LIST (targets);
length = list_length (targets);
n = 0;
- entries = SAFE_ALLOCA (sizeof *entries * length);
+ SAFE_NALLOCA (entries, 1, length);
memset (entries, 0, sizeof *entries * length);
tem = targets;
else
signal_error ("Invalid drag-and-drop action", action);
- target_atoms = SAFE_ALLOCA (ntargets * sizeof *target_atoms);
+ SAFE_NALLOCA (target_atoms, 1, ntargets);
/* Catch errors since interning lots of targets can potentially
generate a BadAlloc error. */
USE_SAFE_ALLOCA;
- submenu_stack = SAFE_ALLOCA (menu_items_used
- * sizeof *submenu_stack);
- subprefix_stack = SAFE_ALLOCA (menu_items_used
- * sizeof *subprefix_stack);
+ SAFE_NALLOCA (submenu_stack, 1, menu_items_used);
+ SAFE_NALLOCA (subprefix_stack, 1, menu_items_used);
specpdl_count = SPECPDL_INDEX ();
#ifdef USE_XCB
USE_SAFE_ALLOCA;
- window_attribute_cookies
- = SAFE_ALLOCA (sizeof *window_attribute_cookies * nitems);
- translate_coordinate_cookies
- = SAFE_ALLOCA (sizeof *translate_coordinate_cookies * nitems);
- get_property_cookies
- = SAFE_ALLOCA (sizeof *get_property_cookies * nitems);
- xm_property_cookies
- = SAFE_ALLOCA (sizeof *xm_property_cookies * nitems);
- extent_property_cookies
- = SAFE_ALLOCA (sizeof *extent_property_cookies * nitems);
- get_geometry_cookies
- = SAFE_ALLOCA (sizeof *get_geometry_cookies * nitems);
+ SAFE_NALLOCA (window_attribute_cookies, 1, nitems);
+ SAFE_NALLOCA (translate_coordinate_cookies, 1, nitems);
+ SAFE_NALLOCA (get_property_cookies, 1, nitems);
+ SAFE_NALLOCA (xm_property_cookies, 1, nitems);
+ SAFE_NALLOCA (extent_property_cookies, 1, nitems);
+ SAFE_NALLOCA (get_geometry_cookies, 1, nitems);
#ifdef HAVE_XCB_SHAPE
- bounding_rect_cookies
- = SAFE_ALLOCA (sizeof *bounding_rect_cookies * nitems);
+ SAFE_NALLOCA (bounding_rect_cookies, 1, nitems);
#endif
#ifdef HAVE_XCB_SHAPE_INPUT_RECTS
- input_rect_cookies
- = SAFE_ALLOCA (sizeof *input_rect_cookies * nitems);
+ SAFE_NALLOCA (input_rect_cookies, 1, nitems);
#endif
for (i = 0; i < nitems; ++i)
if (overflow)
{
- copy_bufptr = SAFE_ALLOCA ((copy_bufsiz += overflow)
- * sizeof *copy_bufptr);
+ copy_bufsiz += overflow;
+ copy_bufptr = SAFE_ALLOCA (copy_bufsiz);
overflow = 0;
/* Use the original keysym derived from the
&overflow);
if (overflow)
{
- copy_bufptr
- = SAFE_ALLOCA ((copy_bufsiz += overflow)
- * sizeof *copy_bufptr);
+ copy_bufsiz += overflow;
+ copy_bufptr = SAFE_ALLOCA (copy_bufsiz);
overflow = 0;
/* Use the original keysym derived from
any_changed = false;
#endif /* !USE_X_TOOLKIT && (!USE_GTK || HAVE_GTK3) */
hev = (XIHierarchyEvent *) xi_event;
- disabled = SAFE_ALLOCA (sizeof *disabled * hev->num_info);
+ SAFE_NALLOCA (disabled, 1, hev->num_info);
n_disabled = 0;
for (i = 0; i < hev->num_info; ++i)
}
#ifdef USE_XCB
- selection_cookies = SAFE_ALLOCA (sizeof *selection_cookies
- * num_fast_selections);
+ SAFE_NALLOCA (selection_cookies, 1, num_fast_selections);
#endif
/* Now, ask for the current owners of all those selections. */