From 3eadc8b0dc290d42e7ecb0aa2fabdfecd1b8236b Mon Sep 17 00:00:00 2001 From: "R. Timothy Edwards" Date: Mon, 8 Jun 2026 14:11:07 -0400 Subject: [PATCH] Corrected some issues in the SPICE parser where a subcircuit name was checked using "subcktname" before its initialization. Added a check for a subcircuit called inside itself, which causes an immediate failure (see issue tracker issue #106). If allowed to continue, netgen will either crash or produce inscrutable output that doesn't pinpoint the issue. --- VERSION | 2 +- base/spice.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index f3b8376..14ba5da 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.5.320 +1.5.321 diff --git a/base/spice.c b/base/spice.c index 4515aae..d7dec64 100644 --- a/base/spice.c +++ b/base/spice.c @@ -1783,10 +1783,19 @@ skip_ends: if (scan->next != NULL) scan = scan->next; tail->next = NULL; + /* Check for class defined inside itself (self-referential loop) */ + + if (!strcasecmp(model, scan->name)) { + Fprintf(stderr, "Fatal: Class \"%s\" is instanced inside of itself!\n", + scan->name); + InputParseError(stderr); + return; + } + /* Check for ignored class */ - if ((itype = IsIgnored(subcktname, filenum)) == IGNORE_CLASS) { - Printf("Class '%s' instanced in input but is being ignored.\n", model); + if ((itype = IsIgnored(scan->name, filenum)) == IGNORE_CLASS) { + Printf("Class '%s' instanced in input but is being ignored.\n", scan->name); return; } @@ -1801,7 +1810,7 @@ skip_ends: break; } if (shorted == (unsigned char)1) { - Printf("Instance of '%s' is shorted, ignoring.\n", subcktname); + Printf("Instance of '%s' is shorted, ignoring.\n", scan->name); while (head) { p = head->next; FREE(head);