|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef MALLOCVAR_INCLUDED |
|
|
#define MALLOCVAR_INCLUDED |
|
|
|
|
|
#include "xmlrpc_config.h" |
|
|
|
|
|
#include <limits.h> |
|
|
#include <stdlib.h> |
|
|
|
|
|
static __inline__ void |
|
|
mallocProduct(void ** const resultP, |
|
|
unsigned int const factor1, |
|
|
size_t const factor2) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (factor1 == 0 || factor2 == 0) |
|
|
*resultP = malloc(1); |
|
|
else { |
|
|
if (UINT_MAX / factor2 < factor1) |
|
|
*resultP = NULL; |
|
|
else |
|
|
*resultP = malloc(factor1 * factor2); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
newBlockP = NULL; |
|
|
else |
|
|
newBlockP = realloc(oldBlockP, factor1 * factor2); |
|
|
|
|
|
if (newBlockP) |
|
|
*blockP = newBlockP; |
|
|
else { |
|
|
free(oldBlockP); |
|
|
*blockP = NULL; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MALLOCARRAY(arrayName, nElements) do { \ |
|
|
void * array; \ |
|
|
mallocProduct(&array, nElements, sizeof(arrayName[0])); \ |
|
|
arrayName = array; \ |
|
|
} while (0) |
|
|
|
|
|
#define REALLOCARRAY(arrayName, nElements) do { \ |
|
|
void * array = arrayName; \ |
|
|
reallocProduct(&array, nElements, sizeof(arrayName[0])); \ |
|
|
arrayName = array; \ |
|
|
} while (0) |
|
|
|
|
|
|
|
|
#define MALLOCARRAY_NOFAIL(arrayName, nElements) \ |
|
|
do { \ |
|
|
MALLOCARRAY(arrayName, nElements); \ |
|
|
if ((arrayName) == NULL) \ |
|
|
abort(); \ |
|
|
} while(0) |
|
|
|
|
|
#define REALLOCARRAY_NOFAIL(arrayName, nElements) \ |
|
|
do { \ |
|
|
REALLOCARRAY(arrayName, nElements); \ |
|
|
if ((arrayName) == NULL) \ |
|
|
abort(); \ |
|
|
} while(0) |
|
|
|
|
|
|
|
|
#define MALLOCVAR(varName) \ |
|
|
varName = malloc(sizeof(*varName)) |
|
|
|
|
|
#define MALLOCVAR_NOFAIL(varName) \ |
|
|
do {if ((varName = malloc(sizeof(*varName))) == NULL) abort();} while(0) |
|
|
|
|
|
#endif |
|
|
|
|
|
|