From 4ce11ba558b943281998a45a1b300e493cfde453 Mon Sep 17 00:00:00 2001 From: Larry Doolittle Date: Tue, 28 Nov 2017 19:58:20 -0800 Subject: Recover centralized xmalloc Now with its sibling xrealloc --- src/vhd2vl.y | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/vhd2vl.y b/src/vhd2vl.y index fbc3688..0848952 100644 --- a/src/vhd2vl.y +++ b/src/vhd2vl.y @@ -36,7 +36,7 @@ void yyerror(const char *s); int vlog_ver=2001; -/* You will of course want to tinker with this if you use a debugging +/* You will of course want to tinker with these if you use a debugging * malloc(), otherwise all the line numbers will point here. */ void *xmalloc(size_t size) { @@ -47,6 +47,15 @@ void *xmalloc(size_t size) { } return p; } +void *xrealloc(void *ptr, size_t size) { + + void *p = realloc(ptr, size); + if (!p) { + perror("realloc"); + exit(2); + } + return p; +} int skipRem = 0; int lineno=1; @@ -138,22 +147,14 @@ void ainit(struct astring *a) a->used = 0; if (!a->s) { a->space = ASTRING_CHUNK; - a->s = malloc(a->space); - if (!a->s) { - fprintf(stderr, "Out of memory asking for %lu in ainit\n", a->space); - exit(2); - } + a->s = xmalloc(a->space); } } void astring_addc(struct astring *a, char c) { if (a->used+1 >= a->space) { a->space += ASTRING_CHUNK; - a->s = realloc(a->s, a->space); - if (!(a->s)) { - fprintf(stderr, "Out of memory asking for %lu in astring_add\n", a->space); - exit(2); - } + a->s = xrealloc(a->s, a->space); } a->s[a->used++] = c; } -- cgit v1.2.1