aboutsummaryrefslogtreecommitdiffstats
path: root/XUtils.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2021-01-11 20:43:27 +0100
committerDaniel Lange <DLange@git.local>2021-01-11 20:43:27 +0100
commitc55320e9e2a8916e911bcd39ab37b79e3a7d03b2 (patch)
treed6be9a09fdf7d6dc155de3429a70697ee2bb43b0 /XUtils.c
parent65357c8c46154de4e4eca14075bfe5523bb5fc14 (diff)
downloaddebian_htop-c55320e9e2a8916e911bcd39ab37b79e3a7d03b2.tar.gz
debian_htop-c55320e9e2a8916e911bcd39ab37b79e3a7d03b2.tar.bz2
debian_htop-c55320e9e2a8916e911bcd39ab37b79e3a7d03b2.zip
New upstream version 3.0.5upstream/3.0.5
Diffstat (limited to 'XUtils.c')
-rw-r--r--XUtils.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/XUtils.c b/XUtils.c
index cd5edb9..01f3342 100644
--- a/XUtils.c
+++ b/XUtils.c
@@ -13,6 +13,7 @@ in the source distribution for its full text.
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -36,9 +37,21 @@ void* xMalloc(size_t size) {
return data;
}
+void* xMallocArray(size_t nmemb, size_t size) {
+ assert(nmemb > 0);
+ assert(size > 0);
+ if (SIZE_MAX / nmemb < size) {
+ fail();
+ }
+ return xMalloc(nmemb * size);
+}
+
void* xCalloc(size_t nmemb, size_t size) {
assert(nmemb > 0);
assert(size > 0);
+ if (SIZE_MAX / nmemb < size) {
+ fail();
+ }
void* data = calloc(nmemb, size);
if (!data) {
fail();
@@ -56,6 +69,15 @@ void* xRealloc(void* ptr, size_t size) {
return data;
}
+void* xReallocArray(void* ptr, size_t nmemb, size_t size) {
+ assert(nmemb > 0);
+ assert(size > 0);
+ if (SIZE_MAX / nmemb < size) {
+ fail();
+ }
+ return xRealloc(ptr, nmemb * size);
+}
+
char* String_cat(const char* s1, const char* s2) {
const size_t l1 = strlen(s1);
const size_t l2 = strlen(s2);

© 2014-2024 Faster IT GmbH | imprint | privacy policy