Fail cleanly on allocation failures
Previously code in the SWIG tool didn't handle allocation failures well. Most places didn't check for NULL return from malloc()/realloc()/calloc() at all, typically resulting in undefined behaviour, and some places used assert() to check for a NULL return (which is a misuse of assert() and such checks disappear if built with NDEBUG defined leaving us back with undefined behaviour). All C allocations are now done via wrapper functions (Malloc(), Realloc() and Calloc()) which emit and error and exit with non-zero status on failure, so a non-NULL return can be relied upon. Fixes #1901.
This commit is contained in:
parent
9eb75a0c07
commit
e38847f7e1
14 changed files with 83 additions and 65 deletions
|
|
@ -173,10 +173,7 @@ static void resize(Hash *h) {
|
|||
p = p + 2;
|
||||
}
|
||||
|
||||
table = (HashNode **) DohMalloc(newsize * sizeof(HashNode *));
|
||||
for (i = 0; i < newsize; i++) {
|
||||
table[i] = 0;
|
||||
}
|
||||
table = (HashNode **) DohCalloc(newsize, sizeof(HashNode *));
|
||||
|
||||
/* Walk down the old set of nodes and re-place */
|
||||
h->hashsize = newsize;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue