From 0e03f0bf9764d8d4aef15499a76da7e0791dbcc2 Mon Sep 17 00:00:00 2001 From: Tim Edwards Date: Tue, 19 Nov 2019 11:45:49 -0500 Subject: [PATCH] Corrected an error that allows a variable to be used uninitialized in parallel_sort, resulting in a (potentially intermittant) segfault condition. --- base/netcmp.c | 10 ++++++---- base/netfile.c | 8 ++++++++ base/verilog.c | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/base/netcmp.c b/base/netcmp.c index 21d048c..1e44368 100644 --- a/base/netcmp.c +++ b/base/netcmp.c @@ -3860,6 +3860,7 @@ void parallel_sort(struct objlist *ob1, struct nlist *tp1, int idx1, int run) cval = 0.0; for (i = 0; i < run; i++) { merge_type = MERGE_NONE; + ml = NULL; for (p = 0;; p++) { vl = &(obp->instance.props[p]); if (vl->type == PROP_ENDLIST) break; @@ -3888,11 +3889,11 @@ void parallel_sort(struct objlist *ob1, struct nlist *tp1, int idx1, int run) } if (merge_type == MERGE_P_ADD) { proplist[i].value = cval * (double)mval; - ml->value.ival = 1; + if (ml) ml->value.ival = 1; } else if (merge_type == MERGE_P_PAR) { proplist[i].value = cval / (double)mval; - ml->value.ival = 1; + if (ml) ml->value.ival = 1; } proplist[i].idx = i; proplist[i].ob = obp; @@ -3904,6 +3905,7 @@ void parallel_sort(struct objlist *ob1, struct nlist *tp1, int idx1, int run) /* and recalculate all the proplist values. */ mval = 1; obp = obn; + ml = NULL; merge_type = MERGE_NONE; for (i = 0; i < run; i++) { for (p = 0;; p++) { @@ -3935,11 +3937,11 @@ void parallel_sort(struct objlist *ob1, struct nlist *tp1, int idx1, int run) } if (merge_type == MERGE_P_ADD) { proplist[i].value = cval * (double)mval; - ml->value.ival = 1; + if (ml) ml->value.ival = 1; } else if (merge_type == MERGE_P_PAR) { proplist[i].value = cval / (double)mval; - ml->value.ival = 1; + if (ml) ml->value.ival = 1; } obp = obp->next; } diff --git a/base/netfile.c b/base/netfile.c index 5dd140e..cf299a9 100644 --- a/base/netfile.c +++ b/base/netfile.c @@ -210,6 +210,7 @@ struct hashdict *definitions = (struct hashdict *)NULL; /*----------------------------------------------------------------------*/ /* TrimQuoted() --- */ /* Remove spaces from inside single- or double-quoted strings. */ +/* Ignore verilog constant bits (e.g., "1'b0") when parsing. */ /*----------------------------------------------------------------------*/ void TrimQuoted(char *line) @@ -225,6 +226,13 @@ void TrimQuoted(char *line) { changed = FALSE; qstart = strchr(lptr, '\''); + if (qstart && (qstart > lptr)) { + if (isdigit(*(qstart - 1))) { + lptr = qstart + 1; + changed = TRUE; + continue; + } + } if (qstart) { qend = strchr(qstart + 1, '\''); diff --git a/base/verilog.c b/base/verilog.c index c9aa988..fe4c979 100644 --- a/base/verilog.c +++ b/base/verilog.c @@ -634,7 +634,7 @@ void ReadVerilogFile(char *fname, int filenum, struct cellstack **CellStackPtr, char *paramval = NULL; // Pick up key = value pairs and store in current cell. Look only - // at the keyword before "=". Then set the defition as everything + // at the keyword before "=". Then set the definition as everything // remaining in the line, excluding comments, until the end-of-statement while (nexttok != NULL)