git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8545 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris
2008-05-23 20:56:24 +00:00
parent d2290cfa3a
commit 00654d880e
338 changed files with 55725 additions and 19400 deletions

View File

@@ -50,14 +50,28 @@ static __inline__ void
reallocProduct(void ** const blockP,
unsigned int const factor1,
unsigned int const factor2) {
void * const oldBlockP = *blockP;
void * newBlockP;
if (UINT_MAX / factor2 < factor1)
*blockP = NULL;
newBlockP = NULL;
else
*blockP = realloc(*blockP, factor1 * factor2);
newBlockP = realloc(oldBlockP, factor1 * factor2);
if (newBlockP)
*blockP = newBlockP;
else {
free(oldBlockP);
*blockP = NULL;
}
}
/* IMPLEMENTATION NOTE: There are huge strict aliasing pitfalls here
if you cast pointers, e.g. (void **)
*/
#define MALLOCARRAY(arrayName, nElements) do { \
void * array; \
@@ -65,8 +79,11 @@ reallocProduct(void ** const blockP,
arrayName = array; \
} while (0)
#define REALLOCARRAY(arrayName, nElements) \
reallocProduct((void **)&arrayName, nElements, sizeof(arrayName[0]))
#define REALLOCARRAY(arrayName, nElements) do { \
void * array = arrayName; \
reallocProduct(&array, nElements, sizeof(arrayName[0])); \
arrayName = array; \
} while (0)
#define MALLOCARRAY_NOFAIL(arrayName, nElements) \