From 1eb2e052bb55184d62c1dec265f6d327be4e9113 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 19 May 2026 18:39:09 -0700 Subject: [PATCH] New function memory_full_up * src/alloc.c (memory_full_up): New function. Replace all callers of memory_full (SIZE_MAX) with callers to this function. This simplifies callers and should make future changes easier. It also saves a whopping 296 bytes in executable size with gcc 16.1.1 20260515 (Red Hat 16.1.1-2) x86-64. --- src/alloc.c | 24 +++++++++++++++++------- src/android.c | 2 +- src/androidselect.c | 2 +- src/androidterm.c | 2 +- src/buffer.c | 6 +++--- src/callint.c | 2 +- src/ccl.c | 2 +- src/coding.c | 2 +- src/composite.c | 2 +- src/dispnew.c | 4 ++-- src/editfns.c | 4 ++-- src/eval.c | 2 +- src/fns.c | 6 +++--- src/gnutls.c | 2 +- src/gtkutil.c | 4 ++-- src/haikufns.c | 2 +- src/haikufont.c | 2 +- src/haikuselect.c | 6 +++--- src/haikuterm.c | 4 ++-- src/image.c | 6 +++--- src/json.c | 2 +- src/keymap.c | 2 +- src/lisp.h | 3 ++- src/macfont.m | 2 +- src/nsfont.m | 2 +- src/pgtkterm.c | 2 +- src/sfntfont-android.c | 4 ++-- src/sfntfont.c | 2 +- src/term.c | 4 ++-- src/timefns.c | 6 +++--- src/tparam.c | 2 +- src/w32term.c | 2 +- src/xselect.c | 6 +++--- src/xsmfns.c | 2 +- src/xterm.c | 2 +- src/xwidget.c | 2 +- 36 files changed, 71 insertions(+), 60 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 5da38cadb5d..a73e7df1dc7 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -711,7 +711,7 @@ xnmalloc (ptrdiff_t nitems, ptrdiff_t item_size) eassert (0 <= nitems && 0 < item_size); ptrdiff_t nbytes; if (ckd_mul (&nbytes, nitems, item_size) || SIZE_MAX < nbytes) - memory_full (SIZE_MAX); + memory_full_up (); return xmalloc (nbytes); } @@ -725,7 +725,7 @@ xnrealloc (void *pa, ptrdiff_t nitems, ptrdiff_t item_size) eassert (0 <= nitems && 0 < item_size); ptrdiff_t nbytes; if (ckd_mul (&nbytes, nitems, item_size) || SIZE_MAX < nbytes) - memory_full (SIZE_MAX); + memory_full_up (); return xrealloc (pa, nbytes); } @@ -792,7 +792,7 @@ xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min, && (ckd_add (&n, n0, nitems_incr_min) || (0 <= nitems_max && nitems_max < n) || ckd_mul (&nbytes, n, item_size))) - memory_full (SIZE_MAX); + memory_full_up (); pa = xrealloc (pa, nbytes); *nitems = n; return pa; @@ -1111,7 +1111,7 @@ lisp_align_malloc (size_t nbytes, enum mem_type type) { lisp_malloc_loser = base; free (base); - memory_full (SIZE_MAX); + memory_full_up (); } } #endif @@ -2181,7 +2181,7 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */) CHECK_FIXNAT (length); EMACS_INT len = XFIXNAT (length); if (BOOL_VECTOR_LENGTH_MAX < len) - memory_full (SIZE_MAX); + memory_full_up (); Lisp_Object val = make_clear_bool_vector (len, NILP (init)); return NILP (init) ? val : bool_vector_fill (val, init); } @@ -2193,7 +2193,7 @@ usage: (bool-vector &rest OBJECTS) */) (ptrdiff_t nargs, Lisp_Object *args) { if (BOOL_VECTOR_LENGTH_MAX < nargs) - memory_full (SIZE_MAX); + memory_full_up (); Lisp_Object vector = make_clear_bool_vector (nargs, true); for (ptrdiff_t i = 0; i < nargs; i++) if (!NILP (args[i])) @@ -3397,7 +3397,7 @@ allocate_clear_vector (ptrdiff_t len, bool clearit) if (len == 0) return XVECTOR (zero_vector); if (VECTOR_ELTS_MAX < len) - memory_full (SIZE_MAX); + memory_full_up (); struct Lisp_Vector *v = allocate_vectorlike (len, clearit); v->header.size = len; return v; @@ -4142,6 +4142,16 @@ memory_full (size_t nbytes) xsignal (Qnil, Vmemory_signal_data); } +/* Report memory exhaustion because size calculations overflowed, + or perhaps malloc was invoked successfully but the + resulting pointer had problems fitting into a tagged EMACS_INT. */ + +void +memory_full_up (void) +{ + memory_full (SIZE_MAX); +} + /* If we released our reserve (due to running out of memory), and we have a fair amount free once again, try to set aside another reserve in case we run out once more. diff --git a/src/android.c b/src/android.c index c1b2b9c98ac..cd950d3c51c 100644 --- a/src/android.c +++ b/src/android.c @@ -4948,7 +4948,7 @@ android_get_image (android_drawable handle, (size_t) bitmap_info.height)) { ANDROID_DELETE_LOCAL_REF (bitmap); - memory_full (0); + memory_full_up (); } } else diff --git a/src/androidselect.c b/src/androidselect.c index 8bdbc0fcd36..ce02c4f42ba 100644 --- a/src/androidselect.c +++ b/src/androidselect.c @@ -618,7 +618,7 @@ does not have any corresponding data. In that case, use if (ckd_add (&length, length, rc) || PTRDIFF_MAX - length < BUFSIZ) - memory_full (PTRDIFF_MAX); + memory_full_up (); if (rc < 0) return unbind_to (ref, Qnil); diff --git a/src/androidterm.c b/src/androidterm.c index a74b595d499..18d6d2eb56a 100644 --- a/src/androidterm.c +++ b/src/androidterm.c @@ -6831,7 +6831,7 @@ android_term_init (void) static char const at[] = " at "; ptrdiff_t nbytes = sizeof (title) + sizeof (at); if (ckd_add (&nbytes, nbytes, SBYTES (system_name))) - memory_full (SIZE_MAX); + memory_full_up (); dpyinfo->x_id_name = xmalloc (nbytes); sprintf (dpyinfo->x_id_name, "%s%s%s", title, at, SDATA (system_name)); diff --git a/src/buffer.c b/src/buffer.c index ec26ff82c78..8963ec4e197 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -3413,7 +3413,7 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, nbytes = SBYTES (str); if (ckd_add (&nbytes, nbytes, ssl->bytes)) - memory_full (SIZE_MAX); + memory_full_up (); ssl->bytes = nbytes; if (STRINGP (str2)) @@ -3427,7 +3427,7 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, nbytes = SBYTES (str2); if (ckd_add (&nbytes, nbytes, ssl->bytes)) - memory_full (SIZE_MAX); + memory_full_up (); ssl->bytes = nbytes; } } @@ -3499,7 +3499,7 @@ overlay_strings (ptrdiff_t pos, struct window *w, unsigned char **pstr) ptrdiff_t total; if (ckd_add (&total, overlay_heads.bytes, overlay_tails.bytes)) - memory_full (SIZE_MAX); + memory_full_up (); if (total > overlay_str_len) overlay_str_buf = xpalloc (overlay_str_buf, &overlay_str_len, total - overlay_str_len, -1, 1); diff --git a/src/callint.c b/src/callint.c index 398bfde468b..1746dd57704 100644 --- a/src/callint.c +++ b/src/callint.c @@ -431,7 +431,7 @@ invoke it (via an `interactive' spec that contains, for instance, an if (MOST_POSITIVE_FIXNUM < min (PTRDIFF_MAX, SIZE_MAX) / word_size && MOST_POSITIVE_FIXNUM < nargs) - memory_full (SIZE_MAX); + memory_full_up (); /* ARGS will contain the array of arguments to pass to the function. VISARGS will contain the same list but in a nicer form, so that if we diff --git a/src/ccl.c b/src/ccl.c index c581d6ecd95..2fe26be5759 100644 --- a/src/ccl.c +++ b/src/ccl.c @@ -2166,7 +2166,7 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY outbufsize = str_bytes; if (ckd_mul (&outbufsize, outbufsize, buf_magnification) || ckd_add (&outbufsize, outbufsize, 256)) - memory_full (SIZE_MAX); + memory_full_up (); outp = outbuf = xmalloc (outbufsize); consumed_chars = consumed_bytes = 0; diff --git a/src/coding.c b/src/coding.c index dd767c80ab4..aea4c0cea5f 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7045,7 +7045,7 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table, ptrdiff_t dst_size; if (ckd_mul (&dst_size, to_nchars, MAX_MULTIBYTE_LENGTH) || ckd_add (&dst_size, dst_size, buf_end - buf)) - memory_full (SIZE_MAX); + memory_full_up (); dst = alloc_destination (coding, dst_size, dst); if (EQ (coding->src_object, coding->dst_object) /* Input and output are not C buffers, which are safe to diff --git a/src/composite.c b/src/composite.c index e36e1670d8d..2898ea9651e 100644 --- a/src/composite.c +++ b/src/composite.c @@ -315,7 +315,7 @@ get_composition_id (ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t nchars, : ASIZE (key)); if (GLYPH_LEN_MAX < glyph_len) - memory_full (SIZE_MAX); + memory_full_up (); /* Register the composition in composition_table. */ cmp = xmalloc (sizeof *cmp); diff --git a/src/dispnew.c b/src/dispnew.c index 284a0eb175f..be15a5ab694 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -1403,7 +1403,7 @@ realloc_glyph_pool (struct glyph_pool *pool, struct dim matrix_dim) /* Enlarge the glyph pool. */ if (ckd_mul (&needed, matrix_dim.height, matrix_dim.width)) - memory_full (SIZE_MAX); + memory_full_up (); if (needed > pool->nglyphs) { ptrdiff_t old_nglyphs = pool->nglyphs; @@ -5412,7 +5412,7 @@ scrolling_window (struct window *w, int tab_line_p) - next_almost_prime_increment_max); ptrdiff_t current_nrows_max = row_table_max - desired_matrix->nrows; if (current_nrows_max < current_matrix->nrows) - memory_full (SIZE_MAX); + memory_full_up (); } /* Reallocate vectors, tables etc. if necessary. */ diff --git a/src/editfns.c b/src/editfns.c index cad41a36f7f..341e241dfcb 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -2080,7 +2080,7 @@ a buffer or a string. But this is deprecated. */) ptrdiff_t bytes_needed; if (ckd_mul (&bytes_needed, diags, 2 * sizeof *buffer) || ckd_add (&bytes_needed, bytes_needed, del_bytes + ins_bytes)) - memory_full (SIZE_MAX); + memory_full_up (); USE_SAFE_ALLOCA; buffer = SAFE_ALLOCA (bytes_needed); unsigned char *deletions_insertions = memset (buffer + 2 * diags, 0, @@ -3510,7 +3510,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message) v |= ckd_add (&alloca_size, info_size, format_and_discarded_size); v |= SIZE_MAX < alloca_size; if (v) - memory_full (SIZE_MAX); + memory_full_up (); /* The info table. */ info = SAFE_ALLOCA (alloca_size); /* A copy of the format string's bytes, needed because the original diff --git a/src/eval.c b/src/eval.c index b61bda4a024..1fdc6653cfc 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1601,7 +1601,7 @@ internal_lisp_condition_case (Lisp_Object var, Lisp_Object bodyform, SAFE_ALLOCA won't work here due to the setjmp, so impose a MAX_ALLOCA limit. */ if (MAX_ALLOCA / word_size < clausenb) - memory_full (SIZE_MAX); + memory_full_up (); Lisp_Object volatile *clauses = alloca (clausenb * sizeof *clauses); clauses += clausenb; *--clauses = make_fixnum (0); diff --git a/src/fns.c b/src/fns.c index a2312ffa1b9..8e7e5f980a1 100644 --- a/src/fns.c +++ b/src/fns.c @@ -902,7 +902,7 @@ concat_to_string (ptrdiff_t nargs, Lisp_Object *args) result_len += len; if (MOST_POSITIVE_FIXNUM < result_len) - memory_full (SIZE_MAX); + memory_full_up (); } if (dest_multibyte && some_unibyte) @@ -1122,7 +1122,7 @@ concat_to_vector (ptrdiff_t nargs, Lisp_Object *args) EMACS_INT len = XFIXNAT (Flength (arg)); result_len += len; if (MOST_POSITIVE_FIXNUM < result_len) - memory_full (SIZE_MAX); + memory_full_up (); } /* Create the output vector. */ @@ -4672,7 +4672,7 @@ larger_vector (Lisp_Object vec, ptrdiff_t incr_min, ptrdiff_t nitems_max) incr_max = n_max - old_size; incr = max (incr_min, min (old_size >> 1, incr_max)); if (incr_max < incr) - memory_full (SIZE_MAX); + memory_full_up (); new_size = old_size + incr; v = allocate_vector (new_size); memcpy (v->contents, XVECTOR (vec)->contents, old_size * sizeof *v->contents); diff --git a/src/gnutls.c b/src/gnutls.c index 4a4567a5174..3ba9b1b290f 100644 --- a/src/gnutls.c +++ b/src/gnutls.c @@ -2424,7 +2424,7 @@ gnutls_symmetric_aead (bool encrypting, gnutls_cipher_algorithm_t gca, ptrdiff_t tagged_size; if (ckd_add (&tagged_size, isize, cipher_tag_size) || SIZE_MAX < tagged_size) - memory_full (SIZE_MAX); + memory_full_up (); size_t storage_length = tagged_size; USE_SAFE_ALLOCA; char *storage = SAFE_ALLOCA (storage_length); diff --git a/src/gtkutil.c b/src/gtkutil.c index 4fc6b3e0108..df41fb91110 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -698,7 +698,7 @@ get_utf8_string (const char *str) if (ckd_mul (&alloc, nr_bad, 4) || ckd_add (&alloc, alloc, len + 1) || SIZE_MAX < alloc) - memory_full (SIZE_MAX); + memory_full_up (); up = utf8_str = xmalloc (alloc); p = (unsigned char *)str; @@ -4382,7 +4382,7 @@ xg_store_widget_in_map (GtkWidget *w) { ptrdiff_t new_size; if (TYPE_MAXIMUM (Window) - ID_TO_WIDGET_INCR < id_to_widget.max_size) - memory_full (SIZE_MAX); + memory_full_up (); new_size = id_to_widget.max_size + ID_TO_WIDGET_INCR; id_to_widget.widgets = xnrealloc (id_to_widget.widgets, diff --git a/src/haikufns.c b/src/haikufns.c index e24dfd2193e..3568c1bc0bc 100644 --- a/src/haikufns.c +++ b/src/haikufns.c @@ -2025,7 +2025,7 @@ haiku_create_colored_cursor (struct user_cursor_bitmap_info *info, bitmap = BBitmap_new (width, height, false); if (!bitmap) - memory_full (SIZE_MAX); + memory_full_up (); for (y = 0; y < height; ++y) { diff --git a/src/haikufont.c b/src/haikufont.c index cc9cb47b395..09edffc08a9 100644 --- a/src/haikufont.c +++ b/src/haikufont.c @@ -1033,7 +1033,7 @@ haikufont_shape (Lisp_Object lgstring, Lisp_Object direction) len = i; if (INT_MAX / 2 < len) - memory_full (SIZE_MAX); + memory_full_up (); block_input (); diff --git a/src/haikuselect.c b/src/haikuselect.c index 93449357806..f8dac897d97 100644 --- a/src/haikuselect.c +++ b/src/haikuselect.c @@ -249,7 +249,7 @@ haiku_message_to_lisp (void *message) case 'MSGG': msg = be_get_message_message (message, name, j); if (!msg) - memory_full (SIZE_MAX); + memory_full_up (); t1 = haiku_message_to_lisp (msg); BMessage_delete (msg); @@ -270,7 +270,7 @@ haiku_message_to_lisp (void *message) } if (!pbuf) - memory_full (SIZE_MAX); + memory_full_up (); t1 = DECODE_FILE (build_string (pbuf)); @@ -837,7 +837,7 @@ haiku_report_system_error (status_t code, const char *format) break; case B_NO_MEMORY: - memory_full (SIZE_MAX); + memory_full_up (); break; default: diff --git a/src/haikuterm.c b/src/haikuterm.c index b2b864188af..065a2d262b2 100644 --- a/src/haikuterm.c +++ b/src/haikuterm.c @@ -2909,7 +2909,7 @@ haiku_define_fringe_bitmap (int which, unsigned short *bits, block_input (); fringe_bmps[which] = BBitmap_new (wd, h, 1); if (!fringe_bmps[which]) - memory_full (SIZE_MAX); + memory_full_up (); BBitmap_import_fringe_bitmap (fringe_bmps[which], bits, wd, h); unblock_input (); } @@ -4526,7 +4526,7 @@ haiku_term_init (void) nbytes = sizeof "GNU Emacs" + sizeof " at "; if (ckd_add (&nbytes, nbytes, SBYTES (system_name))) - memory_full (SIZE_MAX); + memory_full_up (); name_buffer = alloca (nbytes); sprintf (name_buffer, "%s%s%s", "GNU Emacs", diff --git a/src/image.c b/src/image.c index 9d0a620188f..38f9d1416a7 100644 --- a/src/image.c +++ b/src/image.c @@ -6950,7 +6950,7 @@ image_to_emacs_colors (struct frame *f, struct image *img, bool rgb_p) if (ckd_mul (&nbytes, sizeof *colors, img->width) || ckd_mul (&nbytes, nbytes, img->height) || SIZE_MAX < nbytes) - memory_full (SIZE_MAX); + memory_full_up (); colors = xmalloc (nbytes); /* Get the X image or create a memory device context for IMG. */ @@ -7100,7 +7100,7 @@ image_detect_edges (struct frame *f, struct image *img, if (ckd_mul (&nbytes, sizeof *new, img->width) || ckd_mul (&nbytes, nbytes, img->height)) - memory_full (SIZE_MAX); + memory_full_up (); new = xmalloc (nbytes); for (y = 0; y < img->height; ++y) @@ -8486,7 +8486,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c) /* Allocate memory for the image. */ if (ckd_mul (&nbytes, row_bytes, sizeof *pixels) || ckd_mul (&nbytes, nbytes, height)) - memory_full (SIZE_MAX); + memory_full_up (); c->pixels = pixels = xmalloc (nbytes); c->rows = rows = xmalloc (height * sizeof *rows); for (i = 0; i < height; ++i) diff --git a/src/json.c b/src/json.c index ccbbae615d0..9b07f8ced26 100644 --- a/src/json.c +++ b/src/json.c @@ -142,7 +142,7 @@ make_symset_table (int bits, struct symset_tbl *up) { int maxbits = min (SIZE_WIDTH - 2 - (word_size < 8 ? 2 : 3), 32); if (bits > maxbits) - memory_full (PTRDIFF_MAX); /* Will never happen in practice. */ + memory_full_up (); /* Will never happen in practice. */ struct symset_tbl *st = xmalloc (sizeof *st + (sizeof *st->entries << bits)); st->up = up; ptrdiff_t size = symset_size (bits); diff --git a/src/keymap.c b/src/keymap.c index 9c2aa7634fc..dc40d68089a 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -2109,7 +2109,7 @@ For an approximate inverse of this, see `kbd'. */) /* This has one extra element at the end that we don't pass to Fconcat. */ ptrdiff_t size4; if (ckd_mul (&size4, nkeys + nprefix, 4)) - memory_full (SIZE_MAX); + memory_full_up (); SAFE_ALLOCA_LISP (args, size4); /* In effect, this computes diff --git a/src/lisp.h b/src/lisp.h index a5082146da7..bf80cfec3ad 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4430,6 +4430,7 @@ extern void parse_str_as_multibyte (const unsigned char *, ptrdiff_t, extern intptr_t garbage_collection_inhibited; extern void malloc_warning (const char *); extern AVOID memory_full (size_t); +extern AVOID memory_full_up (void); extern AVOID buffer_memory_full (ptrdiff_t); extern bool survives_gc_p (Lisp_Object); extern void mark_object (Lisp_Object); @@ -5704,7 +5705,7 @@ safe_free_unbind_to (specpdl_ref count, specpdl_ref sa_count, Lisp_Object val) ptrdiff_t alloca_nbytes; \ if (ckd_mul (&alloca_nbytes, nelt, word_size) \ || SIZE_MAX < alloca_nbytes) \ - memory_full (SIZE_MAX); \ + memory_full_up (); \ else if (alloca_nbytes <= sa_avail) \ (buf) = AVAIL_ALLOCA (alloca_nbytes); \ else \ diff --git a/src/macfont.m b/src/macfont.m index 84e3e0e8e21..1916e5c0287 100644 --- a/src/macfont.m +++ b/src/macfont.m @@ -3119,7 +3119,7 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no len = i; if (INT_MAX / 2 < len) - memory_full (SIZE_MAX); + memory_full_up (); unichars = alloca (sizeof (UniChar) * (len + nonbmp_len)); nonbmp_indices = alloca (sizeof (CFIndex) * (nonbmp_len + 1)); diff --git a/src/nsfont.m b/src/nsfont.m index 655a4c3b569..71ebf9d8b3d 100644 --- a/src/nsfont.m +++ b/src/nsfont.m @@ -1484,7 +1484,7 @@ is false when (FROM > 0 || TO < S->nchars). */ len = i; if (INT_MAX / 2 < len) - memory_full (SIZE_MAX); + memory_full_up (); block_input (); diff --git a/src/pgtkterm.c b/src/pgtkterm.c index 757ff57a9f2..6362f795eff 100644 --- a/src/pgtkterm.c +++ b/src/pgtkterm.c @@ -7150,7 +7150,7 @@ pgtk_term_init (Lisp_Object display_name, char *resource_name) Lisp_Object system_name = Fsystem_name (); ptrdiff_t nbytes; if (ckd_add (&nbytes, SBYTES (Vinvocation_name), SBYTES (system_name) + 2)) - memory_full (SIZE_MAX); + memory_full_up (); dpyinfo->x_id = ++x_display_id; dpyinfo->x_id_name = xmalloc (nbytes); char *nametail = lispstpcpy (dpyinfo->x_id_name, Vinvocation_name); diff --git a/src/sfntfont-android.c b/src/sfntfont-android.c index 3a5daa67ff8..30cf1876191 100644 --- a/src/sfntfont-android.c +++ b/src/sfntfont-android.c @@ -79,7 +79,7 @@ static size_t max_scanline_buffer_size; size_t _size; \ \ if (ckd_mul (&_size, height, stride)) \ - memory_full (SIZE_MAX); \ + memory_full_up (); \ \ if (_size < MAX_ALLOCA) \ (buffer) = alloca (_size); \ @@ -113,7 +113,7 @@ static size_t max_scanline_buffer_size; void *_temp; \ \ if (ckd_mul (&_size, height, stride)) \ - memory_full (SIZE_MAX); \ + memory_full_up (); \ \ if (_size > scanline_buffer.buffer_size) \ { \ diff --git a/src/sfntfont.c b/src/sfntfont.c index 0cbb41a1f2e..4f49f03d744 100644 --- a/src/sfntfont.c +++ b/src/sfntfont.c @@ -613,7 +613,7 @@ sfnt_parse_languages (struct sfnt_meta_table *meta, /* Now copy metadata and add a trailing NULL byte. */ if (map.data_length >= SIZE_MAX) - memory_full (SIZE_MAX); + memory_full_up (); metadata = SAFE_ALLOCA ((size_t) map.data_length + 1); memcpy (metadata, data, map.data_length); diff --git a/src/term.c b/src/term.c index 354375085e2..e4fdb85831c 100644 --- a/src/term.c +++ b/src/term.c @@ -554,7 +554,7 @@ encode_terminal_code (struct glyph *src, int src_len, Vglyph_table contains a string or a composite glyph is encountered. */ if (ckd_mul (&required, src_len, MAX_MULTIBYTE_LENGTH)) - memory_full (SIZE_MAX); + memory_full_up (); if (encode_terminal_src_size < required) encode_terminal_src = xpalloc (encode_terminal_src, &encode_terminal_src_size, @@ -1245,7 +1245,7 @@ calculate_costs (struct frame *frame) max_frame_cols = max (max_frame_cols, FRAME_COLS (frame)); if ((min (PTRDIFF_MAX, SIZE_MAX) / sizeof (int) - 1) / 2 < max_frame_cols) - memory_full (SIZE_MAX); + memory_full_up (); char_ins_del_vector = xrealloc (char_ins_del_vector, diff --git a/src/timefns.c b/src/timefns.c index 4bfb267c5c1..88f5504fe35 100644 --- a/src/timefns.c +++ b/src/timefns.c @@ -213,7 +213,7 @@ emacs_localtime_rz (timezone_t tz, time_t const *t, struct tm *tm) #endif tm = localtime_rz (tz, t, tm); if (!tm && errno == ENOMEM) - memory_full (SIZE_MAX); + memory_full_up (); return tm; } @@ -317,7 +317,7 @@ tzlookup (Lisp_Object zone, bool settz) if (!new_tz) { if (errno == ENOMEM) - memory_full (SIZE_MAX); + memory_full_up (); invalid_time_zone_specification (zone); } } @@ -367,7 +367,7 @@ time_error (int err) { switch (err) { - case ENOMEM: memory_full (SIZE_MAX); + case ENOMEM: memory_full_up (); case EOVERFLOW: time_overflow (); default: time_spec_invalid (); } diff --git a/src/tparam.c b/src/tparam.c index 261ef02a55e..d37fb67cfac 100644 --- a/src/tparam.c +++ b/src/tparam.c @@ -173,7 +173,7 @@ tparam1 (const char *string, char *outstring, int len, else doleft++, append_len_incr = strlen (left); if (ckd_add (&append_len, append_len, append_len_incr)) - memory_full (SIZE_MAX); + memory_full_up (); } } *op++ = tem ? tem : 0200; diff --git a/src/w32term.c b/src/w32term.c index 43d2440854b..ccf5d14cb10 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -7820,7 +7820,7 @@ w32_initialize_display_info (Lisp_Object display_name) static char const at[] = " at "; ptrdiff_t nbytes = sizeof (title) + sizeof (at); if (ckd_add (&nbytes, nbytes, SCHARS (Vsystem_name))) - memory_full (SIZE_MAX); + memory_full_up (); dpyinfo->w32_id_name = xmalloc (nbytes); sprintf (dpyinfo->w32_id_name, "%s%s%s", title, at, SDATA (Vsystem_name)); } diff --git a/src/xselect.c b/src/xselect.c index 93057c2d6c5..5be009af0d7 100644 --- a/src/xselect.c +++ b/src/xselect.c @@ -1882,7 +1882,7 @@ x_get_window_property (Display *display, Window window, Atom property, if (data) xfree (data); unblock_input (); - memory_full (SIZE_MAX); + memory_full_up (); } /* Use xfree, not XFree, to free the data obtained with this function. */ @@ -1903,7 +1903,7 @@ receive_incremental_selection (struct x_display_info *dpyinfo, Display *display = dpyinfo->display; if (min (PTRDIFF_MAX, SIZE_MAX) < min_size_bytes) - memory_full (SIZE_MAX); + memory_full_up (); *data_ret = xmalloc (min_size_bytes); *size_bytes_ret = min_size_bytes; @@ -3063,7 +3063,7 @@ x_property_data_to_lisp (struct frame *f, const unsigned char *data, ptrdiff_t format_bytes = format >> 3; ptrdiff_t data_bytes; if (ckd_mul (&data_bytes, size, format_bytes)) - memory_full (SIZE_MAX); + memory_full_up (); return selection_data_to_lisp_data (FRAME_DISPLAY_INFO (f), data, data_bytes, type, format); } diff --git a/src/xsmfns.c b/src/xsmfns.c index c3e6224b49a..5fec0e8913e 100644 --- a/src/xsmfns.c +++ b/src/xsmfns.c @@ -224,7 +224,7 @@ smc_save_yourself_CB (SmcConn smcConn, props[props_idx]->type = xstrdup (SmLISTofARRAY8); /* /path/to/emacs, --smid=xxx --no-splash --chdir=dir ... */ if (ckd_add (&i, initial_argc, 3)) - memory_full (SIZE_MAX); + memory_full_up (); props[props_idx]->num_vals = i; vp = xnmalloc (i, sizeof *vp); props[props_idx]->vals = vp; diff --git a/src/xterm.c b/src/xterm.c index b2a0d2cadcc..6580bda9fef 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -30989,7 +30989,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) static char const at[] = " at "; ptrdiff_t nbytes = sizeof (title) + sizeof (at); if (ckd_add (&nbytes, nbytes, SBYTES (system_name))) - memory_full (SIZE_MAX); + memory_full_up (); dpyinfo->x_id_name = xmalloc (nbytes); sprintf (dpyinfo->x_id_name, "%s%s%s", title, at, SDATA (system_name)); } diff --git a/src/xwidget.c b/src/xwidget.c index 0b890375c30..e554dc63bbf 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -2462,7 +2462,7 @@ webkit_js_to_lisp (JSCValue *value) Lisp_Object obj; if (! (0 <= dlen && dlen < G_MAXINT32)) - memory_full (SIZE_MAX); + memory_full_up (); ptrdiff_t n = dlen; struct Lisp_Vector *p = allocate_nil_vector (n);