From: Paul Eggert Date: Sun, 14 Jul 2024 22:37:50 +0000 (+0100) Subject: alloc.c: ckd_add, not by-hand checks X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a51474e9e5f0999dcdf7ff5d24e3cad9a6939eba;p=emacs.git alloc.c: ckd_add, not by-hand checks * src/alloc.c (lmalloc, lrealloc): Prefer ckd_add to by-hand checks for integer addition overflow. (cherry picked from commit b77abd2bfeb13ae046b1f8c6157bd5a497665657) --- diff --git a/src/alloc.c b/src/alloc.c index 37069ee4c9e..52f8a65d59d 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -1404,8 +1404,8 @@ lmalloc (size_t size, bool clearit) if (laligned (p, size) && (MALLOC_0_IS_NONNULL || size || p)) return p; free (p); - size_t bigger = size + LISP_ALIGNMENT; - if (size < bigger) + size_t bigger; + if (!ckd_add (&bigger, size, LISP_ALIGNMENT)) size = bigger; } } @@ -1418,8 +1418,8 @@ lrealloc (void *p, size_t size) p = realloc (p, size); if (laligned (p, size) && (size || p)) return p; - size_t bigger = size + LISP_ALIGNMENT; - if (size < bigger) + size_t bigger; + if (!ckd_add (&bigger, size, LISP_ALIGNMENT)) size = bigger; } }