summaryrefslogtreecommitdiff
path: root/lib/xregcomp.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2022-01-30 15:03:39 +0000
committerColin Watson <cjwatson@debian.org>2022-01-30 15:03:40 +0000
commit43aa5a2b077fafa7b5239302d6e41f42830bf6ac (patch)
treeac58ae008d16b9fe9b02bd4b05ec81ca27de26c0 /lib/xregcomp.c
parentb3f2788945722093b3c9e95eb4905395a634d9f5 (diff)
Simplify static analysis of fatal errors
The usual idiom for fatal error reporting in man-db is `error (FATAL, ...)` (there are a few cases using different exit codes, but they're less common). Unfortunately, there's no easy way to tell the compiler that this call doesn't return, because `error (0, ...)` *does* return. As a result, some call sites required extra work to give the compiler this information, which can sometimes make a difference to static analysis. To simplify this, add a new `fatal` helper function which always exits `FATAL` (i.e. 2) and never returns. This is declared with `_Noreturn` so that the compiler can straightforwardly know what's going on. * bootstrap.conf (gnulib_modules): Add verror. (XGETTEXT_OPTIONS): Add --flag=fatal:2:c-format. * lib/fatal.c, lib/fatal.h: New files. * lib/Makefile.am (libman_la_SOURCES): Add fatal.c and fatal.h. * src/tests/Makefile.am (AM_CPPFLAGS): Add -I$(top_srcdir)/lib. (get_mtime_LDADD): Add $(top_builddir)/lib/libman.la. * lib/pathsearch.c (pathsearch, directory_on_path): Use fatal. * lib/sandbox.c (can_load_seccomp, make_seccomp_filter, _sandbox_load): Likewise. * lib/security.c (gripe_set_euid): Likewise. * lib/xregcomp.c (xregcomp): Likewise. * libdb/db_lookup.c (gripe_corrupt_data, dblookup_pattern): Likewise. * libdb/db_ver.c (dbver_wr): Likewise. * src/accessdb.c (main): Likewise. * src/catman.c (parse_for_sec): Likewise. * src/check_mandirs.c (chown_if_possible): Likewise. * src/man-recode.c (recode): Likewise. * src/man.c (open_cat_stream, format_display, gripe_converting_name): Likewise. * src/manconv.c (add_output): Likewise. * src/manp.c (add_dir_to_path_list): Likewise. * src/tests/get-mtime.c (main): Likewise. * src/whatis.c (do_apropos): Likewise. * src/zsoelim.l (<so>\"?[^ \t\n\"]+\"?): Likewise. * libdb/db_lookup.c (gripe_corrupt_data, gripe_replace_key): Declare as _Noreturn. * src/accessdb.c (main): Remove now-unnecessary assertion. * src/man.c (gripe_converting_name): Remove now-unnecessary abort.
Diffstat (limited to 'lib/xregcomp.c')
-rw-r--r--lib/xregcomp.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/xregcomp.c b/lib/xregcomp.c
index 6d215514..d8e1f180 100644
--- a/lib/xregcomp.c
+++ b/lib/xregcomp.c
@@ -34,7 +34,7 @@
#include "manconfig.h"
-#include "error.h"
+#include "fatal.h"
#include "xalloc.h"
#include "xregcomp.h"
@@ -47,6 +47,6 @@ void xregcomp (regex_t *preg, const char *regex, int cflags)
errstrsize = regerror (err, preg, NULL, 0);
errstr = xmalloc (errstrsize);
regerror (err, preg, errstr, errstrsize);
- error (FATAL, 0, _("fatal: regex `%s': %s"), regex, errstr);
+ fatal (0, _("fatal: regex `%s': %s"), regex, errstr);
}
}