summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2023-05-01 09:06:57 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2023-05-01 11:21:18 -0700
commita1d7a312646ec112140f4a3e112daac2194549df (patch)
tree6ee6795b7f26cf42664ff6d377c94e7ca5eb6ba6
parente915c32cc74671a03a4f656bdbbe9b8103a5ff19 (diff)
downloadgnulib-a1d7a312646ec112140f4a3e112daac2194549df.tar.gz
dynarray: prefer C23 style overflow checking
* lib/malloc/dynarray_emplace_enlarge.c, lib/malloc/dynarray_resize.c: Include stdckdint.h, not intprops.h. * lib/malloc/dynarray_emplace_enlarge.c: (__libc_dynarray_emplace_enlarge): * lib/malloc/dynarray_resize.c (__libc_dynarray_resize): Prefer stdckdint.h to intprops.h macros. * modules/glibc-internal/dynarray (Depends-on): Depend on stdckdint, not intprops.
-rw-r--r--ChangeLog10
-rw-r--r--lib/malloc/dynarray_emplace_enlarge.c4
-rw-r--r--lib/malloc/dynarray_resize.c4
-rw-r--r--modules/glibc-internal/dynarray2
4 files changed, 15 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 0b8e61c123..3528faf40e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2023-05-01 Paul Eggert <eggert@cs.ucla.edu>
+ dynarray: prefer C23 style overflow checking
+ * lib/malloc/dynarray_emplace_enlarge.c, lib/malloc/dynarray_resize.c:
+ Include stdckdint.h, not intprops.h.
+ * lib/malloc/dynarray_emplace_enlarge.c:
+ (__libc_dynarray_emplace_enlarge):
+ * lib/malloc/dynarray_resize.c (__libc_dynarray_resize):
+ Prefer stdckdint.h to intprops.h macros.
+ * modules/glibc-internal/dynarray (Depends-on):
+ Depend on stdckdint, not intprops.
+
mktime: prefer C23 style overflow checking
Prefer stdckdint.h macros to intprops.h macros where either will do,
as this is the C23 standard. Also, it ports around a pcc bug.
diff --git a/lib/malloc/dynarray_emplace_enlarge.c b/lib/malloc/dynarray_emplace_enlarge.c
index 7da539316c..65aabb1e4a 100644
--- a/lib/malloc/dynarray_emplace_enlarge.c
+++ b/lib/malloc/dynarray_emplace_enlarge.c
@@ -22,7 +22,7 @@
#include <dynarray.h>
#include <errno.h>
-#include <intprops.h>
+#include <stdckdint.h>
#include <stdlib.h>
#include <string.h>
@@ -56,7 +56,7 @@ __libc_dynarray_emplace_enlarge (struct dynarray_header *list,
}
size_t new_size;
- if (INT_MULTIPLY_WRAPV (new_allocated, element_size, &new_size))
+ if (ckd_mul (&new_size, new_allocated, element_size))
return false;
void *new_array;
if (list->array == scratch)
diff --git a/lib/malloc/dynarray_resize.c b/lib/malloc/dynarray_resize.c
index 7ecd4de63b..014f98c330 100644
--- a/lib/malloc/dynarray_resize.c
+++ b/lib/malloc/dynarray_resize.c
@@ -22,7 +22,7 @@
#include <dynarray.h>
#include <errno.h>
-#include <intprops.h>
+#include <stdckdint.h>
#include <stdlib.h>
#include <string.h>
@@ -42,7 +42,7 @@ __libc_dynarray_resize (struct dynarray_header *list, size_t size,
over-allocation here. */
size_t new_size_bytes;
- if (INT_MULTIPLY_WRAPV (size, element_size, &new_size_bytes))
+ if (ckd_mul (&new_size_bytes, size, element_size))
{
/* Overflow. */
__set_errno (ENOMEM);
diff --git a/modules/glibc-internal/dynarray b/modules/glibc-internal/dynarray
index 668959482e..f78aea7f1a 100644
--- a/modules/glibc-internal/dynarray
+++ b/modules/glibc-internal/dynarray
@@ -17,8 +17,8 @@ builtin-expect
gen-header
libc-config
stdbool
+stdckdint
stddef
-intprops
configure.ac:
AC_PROG_MKDIR_P