diff options
Diffstat (limited to 'xorg-server/os/utils.c')
-rw-r--r-- | xorg-server/os/utils.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/xorg-server/os/utils.c b/xorg-server/os/utils.c index 75769f17c..7fd395b2a 100644 --- a/xorg-server/os/utils.c +++ b/xorg-server/os/utils.c @@ -1128,10 +1128,20 @@ XNFalloc(unsigned long amount) return ptr; } +/* The original XNFcalloc was used with the xnfcalloc macro which multiplied + * the arguments at the call site without allowing calloc to check for overflow. + * XNFcallocarray was added to fix that without breaking ABI. + */ void * XNFcalloc(unsigned long amount) { - void *ret = calloc(1, amount); + return XNFcallocarray(1, amount); +} + +void * +XNFcallocarray(size_t nmemb, size_t size) +{ + void *ret = calloc(nmemb, size); if (!ret) FatalError("XNFcalloc: Out of memory"); @@ -1148,6 +1158,16 @@ XNFrealloc(void *ptr, unsigned long amount) return ret; } +void * +XNFreallocarray(void *ptr, size_t nmemb, size_t size) +{ + void *ret = reallocarray(ptr, nmemb, size); + + if (!ret) + FatalError("XNFreallocarray: Out of memory"); + return ret; +} + char * Xstrdup(const char *s) { @@ -1640,7 +1660,7 @@ Fclose(void *iop) #include <X11/Xwindows.h> const char * -Win32TempDir() +Win32TempDir(void) { static char buffer[PATH_MAX]; @@ -1981,7 +2001,7 @@ xstrtokenize(const char *str, const char *separators) if (!tmp) goto error; for (tok = strtok(tmp, separators); tok; tok = strtok(NULL, separators)) { - nlist = realloc(list, (num + 2) * sizeof(*list)); + nlist = reallocarray(list, num + 2, sizeof(*list)); if (!nlist) goto error; list = nlist; @@ -2091,6 +2111,7 @@ FormatUInt64Hex(uint64_t num, char *string) string[len] = '\0'; } +#if !defined(WIN32) || defined(__CYGWIN__) /* Move a file descriptor out of the way of our select mask; this * is useful for file descriptors which will never appear in the * select mask to avoid reducing the number of clients that can @@ -2114,3 +2135,4 @@ os_move_fd(int fd) close(fd); return newfd; } +#endif |