summaryrefslogtreecommitdiffstats
path: root/XUtils.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2021-09-10 15:09:42 +0200
committerBenBE <BenBE@geshi.org>2021-09-11 00:04:00 +0200
commitbf395e10c52094c44b1a6e0b7fedc35c35de0641 (patch)
tree6fc0e58e1a31c5c34f8e372b05e449fb2d170070 /XUtils.c
parent8f259bc5e1b9a6a95c16b971cf4733cf76725c96 (diff)
Add xReallocArrayZero() helper
Add helper function to reallocate an dynamic allocated array including zeroing the newly allocated memory.
Diffstat (limited to 'XUtils.c')
-rw-r--r--XUtils.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/XUtils.c b/XUtils.c
index 13327e0f..c589d780 100644
--- a/XUtils.c
+++ b/XUtils.c
@@ -78,6 +78,22 @@ void* xReallocArray(void* ptr, size_t nmemb, size_t size) {
return xRealloc(ptr, nmemb * size);
}
+void* xReallocArrayZero(void* ptr, size_t prevmemb, size_t newmemb, size_t size) {
+ assert((ptr == NULL) == (prevmemb == 0));
+
+ if (prevmemb == newmemb) {
+ return ptr;
+ }
+
+ void* ret = xReallocArray(ptr, newmemb, size);
+
+ if (newmemb > prevmemb) {
+ memset((unsigned char*)ret + prevmemb * size, '\0', (newmemb - prevmemb) * size);
+ }
+
+ return ret;
+}
+
inline bool String_contains_i(const char* s1, const char* s2) {
return strcasestr(s1, s2) != NULL;
}

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