Added a few lines to ResMerge.c which avoid a crash condition when

a resistor subnet has been linked to itself (or something like that).
Otherwise it leads to a double-free and a crash.  This commit does
not address why the subnet was linked to itself, and the crash was
preceded by another internal diagnostic message "Missing rptr at ..."
which has been noted before but still needs to be tracked down and
fixed.  It is likely that a bad output netlist was created, but at
least magic doesn't segfault.
This commit is contained in:
R. Timothy Edwards 2026-06-24 13:51:40 -04:00
parent b266ec6272
commit e7b8e89d2f
1 changed files with 13 additions and 1 deletions

View File

@ -260,7 +260,19 @@ ResSeriesCheck(resptr)
if (rr2->rr_connection1 == resptr)
{
resptr2 = rr1->rr_connection2;
if (rr1->rr_connection2 == rr2->rr_connection2)
if (rr1 == rr2) /* This should not happen, but does? */
{
TxError("Internal error: Resistor linked to itself!\n");
status = LOOP;
ResDeleteResPointer(rr2->rr_connection1, rr2);
ResDeleteResPointer(rr2->rr_connection2, rr2);
resptr2->rn_float.rn_area += rr2->rr_float.rr_area
+ rr2->rr_float.rr_area
+ resptr->rn_float.rn_area;
ResEliminateResistor(rr2, &ResResList);
ResCleanNode(resptr, TRUE, &ResNodeList, &ResNodeQueue);
}
else if (rr1->rr_connection2 == rr2->rr_connection2)
{
status = LOOP;
ResDeleteResPointer(rr1->rr_connection1, rr1);