From 96136258406bc50b31a182c74bad951dbd99b0da Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Thu, 1 Dec 2022 23:17:11 +0100 Subject: [PATCH] Prevent seg fault after strange input like *no circuit .save all .probe alli .op .end --- src/frontend/inpc_probe.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/frontend/inpc_probe.c b/src/frontend/inpc_probe.c index 4f9fef46c..e43bd2256 100644 --- a/src/frontend/inpc_probe.c +++ b/src/frontend/inpc_probe.c @@ -1215,23 +1215,25 @@ static char* get_terminal_number(char* element, char* namestr) Called from inp.c*/ void modprobenames(INPtables* tab) { GENinstance* GENinst; - for (GENinst = tab->defVmod->GENinstances; GENinst; GENinst = GENinst->GENnextInstance) { - char* name = GENinst->GENname; - if (prefix("vcurr_", name)) { - /* copy from char no. 6 to (and excluding) second colon */ - char* endname = strchr(name, ':'); - char* endname2 = strchr(endname + 1, ':'); - /* two-terminal device, one colon, copy all from char no. 6 to (and excluding) colon */ - if (!endname2) { - char* newname = copy_substring(name + 6, endname); - memcpy(name, newname, strlen(newname) + 1); - tfree(newname); - } - /* copy from char no. 6 to (and excluding) second colon */ - else { - char* newname = copy_substring(name + 6, endname2); - memcpy(name, newname, strlen(newname) + 1); - tfree(newname); + if (tab->defVmod) { + for (GENinst = tab->defVmod->GENinstances; GENinst; GENinst = GENinst->GENnextInstance) { + char* name = GENinst->GENname; + if (prefix("vcurr_", name)) { + /* copy from char no. 6 to (and excluding) second colon */ + char* endname = strchr(name, ':'); + char* endname2 = strchr(endname + 1, ':'); + /* two-terminal device, one colon, copy all from char no. 6 to (and excluding) colon */ + if (!endname2) { + char* newname = copy_substring(name + 6, endname); + memcpy(name, newname, strlen(newname) + 1); + tfree(newname); + } + /* copy from char no. 6 to (and excluding) second colon */ + else { + char* newname = copy_substring(name + 6, endname2); + memcpy(name, newname, strlen(newname) + 1); + tfree(newname); + } } } }