From 07b10bc1a18ebb15ae4748b5875bcd90ce53769b Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sun, 23 Jun 2024 11:46:31 +0200 Subject: [PATCH] Bail out when state file is not found. --- src/xspice/icm/digital/d_state/cfunc.mod | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/xspice/icm/digital/d_state/cfunc.mod b/src/xspice/icm/digital/d_state/cfunc.mod index 4666e8b8d..da8413223 100644 --- a/src/xspice/icm/digital/d_state/cfunc.mod +++ b/src/xspice/icm/digital/d_state/cfunc.mod @@ -1690,19 +1690,24 @@ void cm_d_state(ARGS) *s; /* Main string variable. */ static char *open_error = - "\nERROR\n D_STATE: failed to open state file.\n"; + "\nError:\n D_STATE: failed to open state file.\n"; static char *loading_error = - "\nERROR\n D_STATE: state file was not read successfully.\n " + "\nError:\n D_STATE: state file was not read successfully.\n " "The most common cause of this problem is a\n " "trailing blank line in the state.in file.\n"; - /* Allocate storage for the state transition table. */ - table = calloc(1, sizeof (State_Table_t)); - STATIC_VAR(table) = table; /*** open file and count the number of vectors in it ***/ state_file = fopen_with_path( PARAM(state_file), "r"); + if(!state_file) { + cm_message_send(open_error); + cm_cexit(1); + } + + /* Allocate storage for the state transition table. */ + table = calloc(1, sizeof (State_Table_t)); + STATIC_VAR(table) = table; /* increment counter if not a comment until EOF reached... */ i = 0;