added ucrealloc()

This commit is contained in:
git@daemon.de
2014-02-07 16:55:56 +01:00
parent e107759f5b
commit f94a9da803
2 changed files with 15 additions and 0 deletions

View File

@@ -38,5 +38,7 @@ void *ucmalloc(size_t s);
/* the same but it fills the pointer with random values */ /* the same but it fills the pointer with random values */
void *urmalloc(size_t s); void *urmalloc(size_t s);
/* resize a a pointer and fill the added remainder with zeroes */
void *ucrealloc(void *d, size_t oldlen, size_t newlen);
#endif /* _HAVE_PCP_MEM */ #endif /* _HAVE_PCP_MEM */

View File

@@ -52,3 +52,16 @@ void *urmalloc(size_t s) {
} }
void *ucrealloc(void *d, size_t oldlen, size_t newlen) {
newlen = newlen * sizeof(unsigned char);
void *value = realloc (d, newlen);
if (value == NULL) {
err(errno, "Cannot reallocate %ld bytes of memory", newlen);
exit(-1);
}
memset (&value[oldlen], 0, newlen-oldlen);
return value;
}