diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2022-02-24 15:56:08 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2022-02-24 16:28:58 -0500 |
commit | 82f7f9ee1849947ed6de227279e623d8fc3a1ee1 (patch) | |
tree | 479c64bf8d92cfdd1ccba4bd679fb534a943c6e0 /parse.c | |
parent | b490dc534eedcc9878d4962e6d02baf4217a712f (diff) | |
download | bfs-82f7f9ee1849947ed6de227279e623d8fc3a1ee1.tar.xz |
regex: Rework error handling
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -2269,24 +2269,25 @@ static struct expr *parse_regex(struct parser_state *state, int flags, int arg2) goto fail; } - int err; - expr->regex = bfs_regcomp(expr->sdata, state->regex_type, flags, &err); - if (!expr->regex) { - char *str = bfs_regerror(err, NULL); - if (str) { - parse_error(state, "${blu}%s${rs} ${bld}%s${rs}: %s.\n", expr->argv[0], expr->argv[1], str); - free(str); - } else { + if (bfs_regcomp(&expr->regex, expr->sdata, state->regex_type, flags) != 0) { + if (!expr->regex) { + parse_perror(state, "bfs_regcomp()"); + goto fail; + } + + char *str = bfs_regerror(expr->regex); + if (!str) { parse_perror(state, "bfs_regerror()"); + goto fail; } - goto fail_regex; + + parse_error(state, "${blu}%s${rs} ${bld}%s${rs}: %s.\n", expr->argv[0], expr->argv[1], str); + free(str); + goto fail; } return expr; -fail_regex: - free(expr->regex); - expr->regex = NULL; fail: free_expr(expr); return NULL; |