summaryrefslogtreecommitdiff
path: root/man
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-03-03 14:55:19 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-03-07 00:06:24 +0000
commit4ece1c842a08c11c1f84b95355801d41cd8435b1 (patch)
treed6f8fb17a745b9635a837c78046ac325b0505413 /man
parent392eb1cd5f2bdb186f0ff7f51abc4dd05ec13709 (diff)
downloadxorg-lib-libXt-4ece1c842a08c11c1f84b95355801d41cd8435b1.tar.gz
Add XtReallocArray() for overflow checking of multiplied args
Uses reallocarray() if available, otherwise checks for overflow itself, if overflow is possible (i.e. in ILP32 & ILP64 environments, but not LP64 with 32-bit ints). Includes unit tests and XtMallocArray() helper macro. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'man')
-rw-r--r--man/XtMalloc.man25
1 files changed, 14 insertions, 11 deletions
diff --git a/man/XtMalloc.man b/man/XtMalloc.man
index 2fa1d57..bdf580b 100644
--- a/man/XtMalloc.man
+++ b/man/XtMalloc.man
@@ -36,7 +36,7 @@
.na
.TH XtMalloc __libmansuffix__ __xorgversion__ "XT FUNCTIONS"
.SH NAME
-XtMalloc, XtCalloc, XtRealloc, XtFree, XtNew, XtNewString \- memory management functions
+XtMalloc, XtCalloc, XtRealloc, XtReallocArray, XtFree, XtNew, XtNewString \- memory management functions
.SH SYNTAX
#include <X11/Intrinsic.h>
.HP
@@ -44,7 +44,9 @@ char *XtMalloc(Cardinal \fIsize\fP);
.HP
char *XtCalloc(Cardinal \fInum\fP, Cardinal \fIsize\fP);
.HP
-char *XtRealloc(char *\fIptr\fP, Cardinal \fInum\fP);
+char *XtRealloc(char *\fIptr\fP, Cardinal \fIsize\fP);
+.HP
+void *XtReallocArray(void *\fIptr\fP, Cardinal \fInum\fP, Cardinal \fIsize\fP);
.HP
void XtFree(char *\fIptr\fP);
.HP
@@ -55,7 +57,7 @@ String XtNewString(String \fIstring\fP);
Cardinal XtAsprintf(char **\fInew_string\fP, const char *\fIformat\fP, ...);
.SH ARGUMENTS
.IP \fInum\fP 1i
-Specifies the number of bytes or array elements.
+Specifies the number of array elements.
.IP \fIptr\fP 1i
Specifies a pointer to the old storage or to the block of storage that is to be freed.
.IP \fIsize\fP 1i
@@ -90,17 +92,18 @@ calls
.LP
The
.B XtRealloc
-function changes the size of a block of storage (possibly moving it).
-Then, it copies the old contents (or as much as will fit) into the new block
-and frees the old block.
+and
+.B XtReallocArray
+functions change the size of a block of storage (possibly moving it).
+Then, they copy the old contents (or as much as will fit) into the new block
+and free the old block.
If there is insufficient memory to allocate the new block,
-.B XtRealloc
-calls
+or the calculations for the size of the new block would cause an
+integer overflow, these functions call
.BR XtErrorMsg .
If ptr is NULL,
-.B XtRealloc
-allocates the new storage without copying the old contents;
-that is, it simply calls
+these functions allocate the new storage without copying the old contents;
+that is, they simply call
.BR XtMalloc .
.LP
The