2022-08-09 Paul Eggert <eggert@cs.ucla.edu>
+ 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.
+
stdckdint: new module
This supports draft C23 <stdckdint.h>.
* doc/posix-headers/stdckdint.texi:
#include <limits.h>
#include <stdalign.h>
+#include <stdckdint.h>
#include <stdint.h>
-#include "intprops.h"
#include "verify.h"
#if !ALIGNALLOC_VIA_ALIGNED_ALLOC
size_t malloc_size;
unsigned char *q;
- if (INT_ADD_WRAPV (size, alignment, &malloc_size)
+ if (ckd_add (&malloc_size, size, alignment)
|| ! (q = malloc (malloc_size)))
{
errno = ENOMEM;
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
+#include <stdckdint.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "attribute.h"
#include "basename-lgpl.h"
#include "ialloc.h"
-#include "intprops.h"
#include "opendirat.h"
#include "renameatu.h"
if (buffer_size < new_buffer_size)
{
idx_t grown;
- if (! INT_ADD_WRAPV (new_buffer_size, new_buffer_size >> 1, &grown))
+ if (! ckd_add (&grown, new_buffer_size, new_buffer_size >> 1))
new_buffer_size = grown;
char *new_buf = irealloc (buf, new_buffer_size);
if (!new_buf)
#include <errno.h>
#include <ctype.h>
#include <string.h>
+#include <stdckdint.h>
#include <stdlib.h>
#if defined _LIBC || HAVE_ALLOCA
# include <alloca.h>
# include "attribute.h"
#endif
-#include <intprops.h>
#include <flexmember.h>
#ifdef _LIBC
idx_t slen = FLEXSIZEOF (struct patternlist, str, 0); \
idx_t new_used = alloca_used + slen; \
idx_t plensize; \
- if (INT_MULTIPLY_WRAPV (plen, sizeof (CHAR), &plensize) \
- || INT_ADD_WRAPV (new_used, plensize, &new_used)) \
+ if (ckd_mul (&plensize, plen, sizeof (CHAR), &plensize) \
+ || ckd_add (&new_used, new_used, plensize)) \
{ \
retval = -2; \
goto out; \
/* Specification. */
#include <unistd.h>
+#include <stdckdint.h>
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
-#include "intprops.h"
-
/* Most processes have no more than this many groups, and for these
processes we can avoid using malloc. */
enum { GROUPBUF_SIZE = 100 };
{
int n_group_slots = getgroups (0, NULL);
size_t nbytes;
- if (! INT_MULTIPLY_WRAPV (n_group_slots, sizeof *gi->group, &nbytes))
+ if (! ckd_mul (&nbytes, n_group_slots, sizeof *gi->group))
{
gi->group = malloc (nbytes);
if (gi->group)
/* Specification. */
#include "malloca.h"
+#include <stdckdint.h>
+
#include "idx.h"
-#include "intprops.h"
#include "verify.h"
/* The speed critical point in this file is freea() applied to an alloca()
uintptr_t alignment2_mask = 2 * sa_alignment_max - 1;
int plus = sizeof (small_t) + alignment2_mask;
idx_t nplus;
- if (!INT_ADD_WRAPV (n, plus, &nplus) && !xalloc_oversized (nplus, 1))
+ if (!ckd_add (&nplus, n, plus) && !xalloc_oversized (nplus, 1))
{
char *mem = (char *) malloc (nplus);
if (mem != NULL)
{
uintptr_t umem = (uintptr_t)mem, umemplus;
- /* The INT_ADD_WRAPV avoids signed integer overflow on
+ /* The ckd_add avoids signed integer overflow on
theoretical platforms where UINTPTR_MAX <= INT_MAX. */
- INT_ADD_WRAPV (umem, sizeof (small_t) + sa_alignment_max - 1,
- &umemplus);
+ ckd_add (&umemplus, umem, sizeof (small_t) + sa_alignment_max - 1);
idx_t offset = ((umemplus & ~alignment2_mask)
+ sa_alignment_max - umem);
void *vp = mem + offset;
#include "c-ctype.h"
#include "idx.h"
-#include "intprops.h"
#include "verify.h"
+#include <stdckdint.h>
#include <string.h>
/*
| (tm0.tm_min ^ tm1.tm_min)
| (tm0.tm_sec ^ tm1.tm_sec)))
{
- if (INT_ADD_WRAPV (t, leapsec, &t))
+ if (ckd_add (&t, t, leapsec))
return false;
*p = t;
return true;
#include <config.h>
+#include <stdckdint.h>
#include <stdlib.h>
#include <errno.h>
-#include "intprops.h"
-
void *
reallocarray (void *ptr, size_t nmemb, size_t size)
{
size_t nbytes;
- if (INT_MULTIPLY_WRAPV (nmemb, size, &nbytes))
+ if (ckd_mul (&nbytes, nmemb, size))
{
errno = ENOMEM;
return NULL;
#include "xalloc.h"
#include "ialloc.h"
-#include "intprops.h"
#include "minmax.h"
+#include <stdckdint.h>
#include <stdlib.h>
#include <string.h>
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 ();
}
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;
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)
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;
extensions
extern-inline
idx
-intprops
posix_memalign
stdalign
+stdckdint
stdint
verify
d-ino
fcntl-h
ialloc
-intprops
memcmp
opendirat
readdir
renameatu
stdbool
+stdckdint
stdint
xalloc-oversized
d-ino
fcntl-h
ialloc
-intprops
memcmp
opendirat
readdir
realloc-gnu
renameatu
stdbool
+stdckdint
stdint
xalloc-die
builtin-expect [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
flexmember [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
idx [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
-intprops [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
isblank [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
iswctype [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
libc-config [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
stdbool [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
+stdckdint [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
strnlen [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
wchar [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
wctype-h [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
unistd
extensions
getgroups [test $HAVE_GROUP_MEMBER = 0]
-intprops [test $HAVE_GROUP_MEMBER = 0]
realloc-gnu [test $HAVE_GROUP_MEMBER = 0]
+stdckdint [test $HAVE_GROUP_MEMBER = 0]
configure.ac:
gl_FUNC_GROUP_MEMBER
Depends-on:
alloca-opt
idx
-intprops
+stdckdint
stdint
verify
xalloc-oversized
Depends-on:
c-ctype
idx
-intprops
mktime
stdbool
+stdckdint
verify
configure.ac:
Depends-on:
extensions
-intprops [test $HAVE_REALLOCARRAY = 0 || test $REPLACE_REALLOCARRAY = 1]
realloc-gnu [test $HAVE_REALLOCARRAY = 0 || test $REPLACE_REALLOCARRAY = 1]
+stdckdint [test $HAVE_REALLOCARRAY = 0 || test $REPLACE_REALLOCARRAY = 1]
stdlib
configure.ac:
stdalign
stdbool
stddef
+stdckdint
stdint
stdlib
string
extern-inline
ialloc
idx
-intprops
malloc-gnu
minmax
realloc-gnu
reallocarray
+stdckdint
stdint
xalloc-die