Commit 57fc1a5f authored by Paul Eggert's avatar Paul Eggert
Browse files

Prefer signed when testing for signed overflow

* src/alloc.c (free_cons):
* src/casefiddle.c (do_casify_multibyte_string):
* src/editfns.c (styled_format):
* src/image.c (png_load_body):
Use signed arguments to INT_MULTIPLY_WRAPV etc.  This doesn’t fix
any bugs, but GCC emits better code when all args are signed.
Also, this removes the need for an if in free_cons (Bug#37006).
parent f01365f6
Pipeline #2817 failed with stage
in 53 minutes and 49 seconds
......@@ -2542,9 +2542,8 @@ free_cons (struct Lisp_Cons *ptr)
ptr->u.s.u.chain = cons_free_list;
ptr-> = dead_object ();
cons_free_list = ptr;
if (consing_until_gc <= 0)
consing_until_gc += sizeof *ptr;
else if (INT_ADD_WRAPV (consing_until_gc, sizeof *ptr, &consing_until_gc))
int incr = sizeof *ptr;
if (INT_ADD_WRAPV (consing_until_gc, incr, &consing_until_gc))
consing_until_gc = OBJECT_CT_MAX;
......@@ -265,8 +265,9 @@ do_casify_multibyte_string (struct casing_context *ctx, Lisp_Object obj)
ptrdiff_t size = SCHARS (obj), n;
ptrdiff_t casing_str_buf_size = sizeof (struct casing_str_buf);
|| INT_ADD_WRAPV (n, sizeof (struct casing_str_buf), &n))
|| INT_ADD_WRAPV (n, casing_str_buf_size, &n))
unsigned char *dst = SAFE_ALLOCA (n);
unsigned char *dst_end = dst + n;
......@@ -3159,8 +3159,8 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
ptrdiff_t nspec_bound = SCHARS (args[0]) >> 1;
/* Allocate the info and discarded tables. */
ptrdiff_t info_size, alloca_size;
if (INT_MULTIPLY_WRAPV (nspec_bound, sizeof *info, &info_size)
ptrdiff_t info_size = sizeof *info, alloca_size;
if (INT_MULTIPLY_WRAPV (nspec_bound, info_size, &info_size)
|| INT_ADD_WRAPV (formatlen, info_size, &alloca_size)
|| SIZE_MAX < alloca_size)
memory_full (SIZE_MAX);
......@@ -6463,7 +6463,6 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
png_uint_32 row_bytes;
bool transparent_p;
struct png_memory_storage tbr; /* Data to be read */
ptrdiff_t nbytes;
Emacs_Pix_Container ximg, mask_img = NULL;
/* Find out what file to load. */
......@@ -6660,7 +6659,8 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
row_bytes = png_get_rowbytes (png_ptr, info_ptr);
/* Allocate memory for the image. */
if (INT_MULTIPLY_WRAPV (row_bytes, sizeof *pixels, &nbytes)
ptrdiff_t nbytes = sizeof *pixels;
if (INT_MULTIPLY_WRAPV (row_bytes, nbytes, &nbytes)
|| INT_MULTIPLY_WRAPV (nbytes, height, &nbytes))
memory_full (SIZE_MAX);
c->pixels = pixels = xmalloc (nbytes);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment