summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-12-03 06:24:38 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:06:18 -0500
commit58c326809a816703dc516c3022c9c4dbb9d09445 (patch)
tree3900a7b59edf075e09459e0bf5f85097396bd9aa /source4/lib
parentc9932a3a92dd7b8696e4e145c7d7e2c080b46ffb (diff)
downloadsamba-58c326809a816703dc516c3022c9c4dbb9d09445.tar.gz
samba-58c326809a816703dc516c3022c9c4dbb9d09445.tar.bz2
samba-58c326809a816703dc516c3022c9c4dbb9d09445.zip
r4052: fixed a bunch of code to use the type safe _p allocation macros
(This used to be commit 80d15fa3402a9d1183467463f6b21c0b674bc442)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/util.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/source4/lib/util.c b/source4/lib/util.c
index 2351a98eae..2d149e6e3d 100644
--- a/source4/lib/util.c
+++ b/source4/lib/util.c
@@ -796,3 +796,20 @@ BOOL all_zero(const uint8_t *ptr, uint_t size)
}
return True;
}
+
+/*
+ realloc an array, checking for integer overflow in the array size
+*/
+void *realloc_array(void *ptr, size_t el_size, unsigned count)
+{
+#define MAX_MALLOC_SIZE 0x7fffffff
+ if (count == 0 ||
+ count >= MAX_MALLOC_SIZE/el_size) {
+ return NULL;
+ }
+ if (!ptr) {
+ return malloc(el_size * count);
+ }
+ return realloc(ptr, el_size * count);
+}
+