summaryrefslogtreecommitdiff
path: root/lib/xalloc-oversized.h
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-04-24 18:13:40 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2021-04-24 18:14:06 -0700
commit724f02cffadca0f63828537d018247f48ee115c0 (patch)
tree9b99b281db18c575d5294bf8eb1cc32887ee2023 /lib/xalloc-oversized.h
parentcc98a5e2fd16ae8589deea9dbd71be59b6f77305 (diff)
downloadgnulib-724f02cffadca0f63828537d018247f48ee115c0.tar.gz
xmalloca, etc.: avoid unlikely trap
* lib/xmalloca.h (xnmalloca): Use size_t, not ptrdiff_t, to avoid implementation-defined behavior (which could include a trap) if N is 0 and S exceeds PTRDIFF_MAX. * lib/xalloc-oversized.h: Adjust comment to match.
Diffstat (limited to 'lib/xalloc-oversized.h')
-rw-r--r--lib/xalloc-oversized.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/xalloc-oversized.h b/lib/xalloc-oversized.h
index 62f1ae94b8..2619a2aab4 100644
--- a/lib/xalloc-oversized.h
+++ b/lib/xalloc-oversized.h
@@ -38,8 +38,8 @@
Warning: (xalloc_oversized (N, S) ? NULL : malloc (N * S)) can
misbehave if N and S are both narrower than ptrdiff_t and size_t,
- and can be rewritten as (xalloc_oversized (N, S) ? NULL : malloc
- (N * (ptrdiff_t) S)) or similarly with size_t.
+ and can be rewritten as (xalloc_oversized (N, S) ? NULL
+ : malloc (N * (size_t) S)).
This is a macro, not a function, so that it works even if an
argument exceeds MAX (PTRDIFF_MAX, SIZE_MAX). */