--- ray/src/common/ealloc.c 2003/04/23 00:52:33 2.4 +++ ray/src/common/ealloc.c 2022/01/19 00:59:33 2.11 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: ealloc.c,v 2.4 2003/04/23 00:52:33 greg Exp $"; +static const char RCSid[] = "$Id: ealloc.c,v 2.11 2022/01/19 00:59:33 greg Exp $"; #endif /* * ealloc.c - memory routines which call quit on error. @@ -11,73 +11,69 @@ static const char RCSid[] = "$Id: ealloc.c,v 2.4 2003/ #include #include +#include "rterror.h" +#include "rtmisc.h" -char * -emalloc(n) /* return pointer to n uninitialized bytes */ -unsigned int n; +void * /* return pointer to n uninitialized bytes */ +emalloc(size_t n) { - register char *cp; + void *cp; if (n == 0) return(NULL); - if ((cp = (char *)malloc(n)) != NULL) + if ((cp = malloc(n)) != NULL) return(cp); eputs("Out of memory in emalloc\n"); quit(1); + return NULL; /* pro forma return */ } -char * -ecalloc(ne, es) /* return pointer to initialized memory */ -register unsigned int ne; -unsigned int es; +void * /* return pointer to initialized memory */ +ecalloc(size_t ne, size_t es) { - register char *cp; + void *cp; - ne *= es; - if (ne == 0) + if (!ne | !es) return(NULL); - if ((cp = (char *)malloc(ne)) == NULL) { - eputs("Out of memory in ecalloc\n"); - quit(1); - } - cp += ne; - while (ne--) - *--cp = 0; - return(cp); + if ((cp = calloc(ne, es)) != NULL) + return(cp); + + eputs("Out of memory in ecalloc\n"); + quit(1); + return(NULL); /* pro forma return */ } -char * -erealloc(cp, n) /* reallocate cp to size n */ -register char *cp; -unsigned int n; +void * /* reallocate cp to size n */ +erealloc(void *cp, size_t n) { if (n == 0) { if (cp != NULL) - free((void *)cp); + free(cp); return(NULL); } if (cp == NULL) - cp = (char *)malloc(n); + cp = malloc(n); else - cp = (char *)realloc((void *)cp, n); + cp = realloc(cp, n); if (cp != NULL) return(cp); eputs("Out of memory in erealloc\n"); quit(1); + return NULL; /* pro forma return */ } -void -efree(cp) /* free memory allocated by above */ -char *cp; +void /* free memory allocated by above */ +efree(void *cp) { - free((void *)cp); + if (cp) + free(cp); }