diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2022-08-09 23:20:49 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2022-08-10 00:22:09 -0700 |
commit | ef5a4088d9236a55283d1eb576f560aa39c09e6f (patch) | |
tree | 8e385baed75dfd2ea33ce069e66f013146cb40d9 /lib/xmalloc.c | |
parent | 2eb92c362ecfb2dae9c9cb37cb9246df6989181c (diff) | |
download | gnulib-ef5a4088d9236a55283d1eb576f560aa39c09e6f.tar.gz |
stdckdint: prefer to intprops when easy
stdckdint.h is part of draft C23 and therefore is more likely
to be familiar to programmers in the future, so prefer it to
intprops.h in files that don’t need non-_WRAPV intprops.h macros.
* lib/alignalloc.c, lib/backupfile.c, lib/fnmatch.c, lib/fnmatch_loop.c:
* lib/group-member.c, lib/malloca.c, lib/posixtm.c, lib/reallocarray.c:
* lib/xmalloc.c:
For files that can use stdckdint.h just as easily as intprops.h,
include the former instead of the latter, and use the former’s
ckd_* macros instead of the latter’s *_WRAPV macros.
* modules/alignalloc, modules/backup-rename, modules/backupfile:
* modules/fnmatch, modules/group-member, modules/malloca:
* modules/posixtm, modules/reallocarray:
* modules/relocatable-prog-wrapper, modules/xalloc:
Depend on stdckdint instead of intprops.
Diffstat (limited to 'lib/xmalloc.c')
-rw-r--r-- | lib/xmalloc.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/xmalloc.c b/lib/xmalloc.c index 993c1eeb75..3c3cb20799 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c @@ -22,9 +22,9 @@ #include "xalloc.h" #include "ialloc.h" -#include "intprops.h" #include "minmax.h" +#include <stdckdint.h> #include <stdlib.h> #include <string.h> @@ -195,7 +195,7 @@ x2nrealloc (void *p, size_t *pn, size_t s) else { /* Set N = floor (1.5 * N) + 1 to make progress even if N == 0. */ - if (INT_ADD_WRAPV (n, (n >> 1) + 1, &n)) + if (ckd_add (&n, n, (n >> 1) + 1)) xalloc_die (); } @@ -236,7 +236,7 @@ xpalloc (void *pa, idx_t *pn, idx_t n_incr_min, ptrdiff_t n_max, idx_t s) N_MAX, and what the C language can represent safely. */ idx_t n; - if (INT_ADD_WRAPV (n0, n0 >> 1, &n)) + if (ckd_add (&n, n0, n0 >> 1)) n = IDX_MAX; if (0 <= n_max && n_max < n) n = n_max; @@ -251,7 +251,7 @@ xpalloc (void *pa, idx_t *pn, idx_t n_incr_min, ptrdiff_t n_max, idx_t s) size_t nbytes; #endif idx_t adjusted_nbytes - = (INT_MULTIPLY_WRAPV (n, s, &nbytes) + = (ckd_mul (&nbytes, n, s) ? MIN (IDX_MAX, SIZE_MAX) : nbytes < DEFAULT_MXFAST ? DEFAULT_MXFAST : 0); if (adjusted_nbytes) @@ -263,9 +263,9 @@ xpalloc (void *pa, idx_t *pn, idx_t n_incr_min, ptrdiff_t n_max, idx_t s) if (! pa) *pn = 0; if (n - n0 < n_incr_min - && (INT_ADD_WRAPV (n0, n_incr_min, &n) + && (ckd_add (&n, n0, n_incr_min) || (0 <= n_max && n_max < n) - || INT_MULTIPLY_WRAPV (n, s, &nbytes))) + || ckd_mul (&nbytes, n, s))) xalloc_die (); pa = xrealloc (pa, nbytes); *pn = n; |