| txreallocarray.c - numtools - perform numerical operations on vectors and matri… | |
| git clone git://src.adamsgaard.dk/numtools | |
| Log | |
| Files | |
| Refs | |
| README | |
| LICENSE | |
| --- | |
| txreallocarray.c (287B) | |
| --- | |
| 1 #include <err.h> | |
| 2 #include <stdlib.h> | |
| 3 | |
| 4 void * | |
| 5 xreallocarray(void *m, size_t n, size_t s) | |
| 6 { | |
| 7 void *nm; | |
| 8 | |
| 9 if (n == 0 || s == 0) { | |
| 10 free(m); | |
| 11 return NULL; | |
| 12 } | |
| 13 if (s && n > (size_t) - 1 / s) | |
| 14 err(1, "realloc: overflow"); | |
| 15 if (!(nm = realloc(m, n * s))) | |
| 16 err(1, "realloc"); | |
| 17 | |
| 18 return nm; | |
| 19 } |