summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLarry Doolittle <ldoolitt@recycle.lbl.gov>2017-11-28 19:58:20 -0800
committerLarry Doolittle <ldoolitt@recycle.lbl.gov>2017-11-28 19:58:20 -0800
commit4ce11ba558b943281998a45a1b300e493cfde453 (patch)
treed8a9170251af667ce75cd62fd5b205c006234178
parent0c85b5b9d195c0aacd96e223c31e54d77b5a2bfc (diff)
downloadvhdl2vl-4ce11ba558b943281998a45a1b300e493cfde453.tar.gz
vhdl2vl-4ce11ba558b943281998a45a1b300e493cfde453.zip
Recover centralized xmalloc
Now with its sibling xrealloc
-rw-r--r--src/vhd2vl.y23
1 files 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;
}
OpenPOWER on IntegriCloud