ngspice segfaults when an invalid OSDI .model card is declared after a valid
card. Changing only the order of the model cards changes a clean error into a
crash.
I have attached four files:
demo_diode.va: minimal Verilog-A model; parameter n has the valid range(0:10).demo_diode.osdi: compiled x86-64 OSDI model.clean_invalid_then_valid.cir: reports Parameter n is out of bounds! andcrash_valid_then_invalid.cir: segfaults with exit code 139.Both netlists use the same invalid value, n=100. Only the order of the two
.model cards differs. Load demo_diode.osdi before running the netlists.
I reproduced this with ngspice-44.2 and ngspice-47 on Linux x86-64.
I believe the bug is in OSDIsetup() in src/osdi/osdisetup.c. After
setup_model() fails, continue skips initialization for the failed model, and
a later successful model overwrites the error stored in res. The simulation
then proceeds with uninitialized Jacobian pointers and crashes in
load_jacobian_resist.
Thanks for the report.
Is there any reason (from user perspective) to not bail out immediately in case of such a model parameter error?
I think it would be perfectly reasonable to fail immediately once an
invalid model parameter is detected.
Last edit: Holger Vogt 2026-08-14
I have uploaded a fix to ngspice git branch pre-master-48.