From: Jouni Malinen Date: Mon, 13 Aug 2012 18:20:09 +0000 (+0300) Subject: Add os_realloc_array() wrapper X-Git-Tag: hostap_2_0~427 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0cda9bd4662b6cfa0684b933fb9a12a84642e11;p=thirdparty%2Fhostap.git Add os_realloc_array() wrapper This function can be used as a wrapper for os_realloc(ptr, nmemb * size) when a reallocation is used for an array. The main benefit over os_realloc() is in having an extra check to catch integer overflows in multiplication. This is similar to the os_zalloc() to os_calloc() move. Signed-hostap: Jouni Malinen --- diff --git a/src/utils/os.h b/src/utils/os.h index 468f66f45..ad208341f 100644 --- a/src/utils/os.h +++ b/src/utils/os.h @@ -486,6 +486,14 @@ char * os_strdup(const char *s); #endif /* OS_NO_C_LIB_DEFINES */ +static inline void * os_realloc_array(void *ptr, size_t nmemb, size_t size) +{ + if (size && nmemb > (~(size_t) 0) / size) + return NULL; + return os_realloc(ptr, nmemb * size); +} + + /** * os_strlcpy - Copy a string with size bound and NUL-termination * @dest: Destination