From f2ac0826ded9415354fc81e048802e919f1538aa Mon Sep 17 00:00:00 2001 From: Scott Vokes Date: Mon, 14 Oct 2024 11:03:02 -0400 Subject: [PATCH 1/2] tmp: Add EXPENSIVE_CHECKS wrapper around fsm_exec's is_isdfa check. Normally this doesn't matter, because the expected API use is based on code generation rather than heavily using `fsm_exec`, but we are calling fsm_exec to check that the combined DFAs still match all of their original regexes. This is very expensive. (It similarly gets very cumbersome during fuzzing.) A better way to address this long-term is tracking on the FSM whether it's result of fsm_determinise (and optionally fsm_minimise), and updating that info to indicate that it reverted to an NFA if any other operations modify the FSM states/edges. That's outside the scope of this PR though. --- src/libfsm/exec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libfsm/exec.c b/src/libfsm/exec.c index 077494b8f..e74cf7c7c 100644 --- a/src/libfsm/exec.c +++ b/src/libfsm/exec.c @@ -105,10 +105,12 @@ fsm_exec(const struct fsm *fsm, /* TODO: pass struct of callbacks to call during each event; transitions etc */ +#if EXPENSIVE_CHECKS if (!fsm_all(fsm, fsm_isdfa)) { errno = EINVAL; return -1; } +#endif if (!fsm_getstart(fsm, &state)) { errno = EINVAL; From 03033cc7196b2663d9953055d1a432fc7b6433dc Mon Sep 17 00:00:00 2001 From: Scott Vokes Date: Mon, 14 Oct 2024 11:12:32 -0400 Subject: [PATCH 2/2] cdata: Address warning, ensure closing `}` is always output. Previously `AMBIG_NONE` was missing the closing curly brace but the other variants added it. All three need it, so it's cleaner to move it outside the switch case. Also, make AMBIG_NONE output `(void)endid_base;`, because otherwise it leads to a warning about the unused variable. (It's probably not worth complicating the output template further to avoid using it in the first place here.) --- src/libfsm/print/cdata.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libfsm/print/cdata.c b/src/libfsm/print/cdata.c index b8ec31234..16c59d6cd 100644 --- a/src/libfsm/print/cdata.c +++ b/src/libfsm/print/cdata.c @@ -604,21 +604,21 @@ generate_interpreter(FILE *f, const struct cdata_config *config, const struct fs switch (opt->ambig) { case AMBIG_NONE: + fprintf(f, + "\t\t(void)endid_base;\n"); break; case AMBIG_ERROR: case AMBIG_EARLIEST: fprintf(f, "\t\t*id = *endid_base;\n" - "\t\t(void)endid_count;\n" - "\t}\n"); + "\t\t(void)endid_count;\n"); break; case AMBIG_MULTIPLE: fprintf(f, "\t\t*%s = endid_base;\n" - "\t\t*%s = endid_count;\n" - "\t}\n", + "\t\t*%s = endid_count;\n", /* TODO: rename these to endid_ids and endid_count? * That will be an interface change. */ "ids", "count"); @@ -628,6 +628,9 @@ generate_interpreter(FILE *f, const struct cdata_config *config, const struct fs assert(!"unreached"); abort(); } + + fprintf(f, + "\t}\n"); } /* If the end state has eager_outputs, set their flags. */