Skip to content

Commit 957dcbf

Browse files
walacglemco
authored andcommitted
rv/rvgen: enforce presence of initial state
The __get_state_variables() method parses DOT files to identify the automaton's initial state. If the input file lacks a node with the required initialization prefix, the initial_state variable is referenced before assignment, causing an UnboundLocalError or a generic error during the state removal step. Initialize the variable explicitly and validate that a start node was found after parsing. Raise a descriptive AutomataError if the definition is missing to improve debugging and ensure the automaton is valid. Signed-off-by: Wander Lairson Costa <wander@redhat.com> Reviewed-by: Gabriele Monaco <gmonaco@redhat.com> Link: https://lore.kernel.org/r/20260223162407.147003-18-wander@redhat.com Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
1 parent 2074723 commit 957dcbf

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

tools/verification/rvgen/rvgen/automata.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def __get_state_variables(self) -> tuple[list[str], str, list[str]]:
145145
# wait for node declaration
146146
states = []
147147
final_states = []
148+
initial_state = ""
148149

149150
has_final_states = False
150151
cursor = self.__get_cursor_begin_states()
@@ -171,6 +172,9 @@ def __get_state_variables(self) -> tuple[list[str], str, list[str]]:
171172
final_states.append(state)
172173
has_final_states = True
173174

175+
if not initial_state:
176+
raise AutomataError("The automaton doesn't have an initial state")
177+
174178
states = sorted(set(states))
175179
states.remove(initial_state)
176180

0 commit comments

Comments
 (0)