diff options
author | Kelvin M. Klann <kmk3.code@protonmail.com> | 2024-01-29 03:49:44 -0300 |
---|---|---|
committer | Kelvin M. Klann <kmk3.code@protonmail.com> | 2024-02-19 17:20:13 -0300 |
commit | f7da0e74d717bf668740233f72e3f2c1ec882129 (patch) | |
tree | 30c9cb8689c3f22224597eaac4017483bc0e1084 | |
parent | build(deps): bump github/codeql-action from 3.24.0 to 3.24.3 (diff) | |
download | firejail-f7da0e74d717bf668740233f72e3f2c1ec882129.tar.gz firejail-f7da0e74d717bf668740233f72e3f2c1ec882129.tar.zst firejail-f7da0e74d717bf668740233f72e3f2c1ec882129.zip |
build: move errExit macro into inline function
Move most of the `errExit` macro into a new `_errExit` inline function
and use the former just to forward arguments to the latter.
This reduces the noise in the build output when using `-fanalyzer`, as
it causes the `errExit` macro to stop being expanded.
For example, the complete output of the following warning in
src/firejail/dbus.c is reduced from 243 lines to 141 lines (a ~41%
reduction):
$ pacman -Q gcc
gcc 13.2.1-5
$ ./configure --enable-apparmor --enable-analyzer >/dev/null &&
make clean >/dev/null && make >/dev/null
[...]
../../src/firejail/dbus.c: In function ‘dbus_proxy_start’:
../../src/firejail/dbus.c:311:36: warning: leak of file descriptor ‘dup2(output_fd, 1)’ [CWE-775] [-Wanalyzer-fd-leak]
311 | if (dup2(output_fd, STDOUT_FILENO) != STDOUT_FILENO)
[...]
‘dbus_create_user_dir’: event 5
|
|../../src/firejail/../include/common.h:42:25:
| 42 | #define errExit(msg) do { \
| | ^
| | |
| | (5) ...to here
../../src/firejail/dbus.c:239:17: note: in expansion of macro ‘errExit’
| 239 | errExit("asprintf");
| | ^~~~~~~
[...]
Relates to #6190.
-rw-r--r-- | src/include/common.h | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/include/common.h b/src/include/common.h index 5f09fe3e2..61a27ded9 100644 --- a/src/include/common.h +++ b/src/include/common.h | |||
@@ -39,13 +39,15 @@ | |||
39 | // dbus proxy path used by firejail and firemon | 39 | // dbus proxy path used by firejail and firemon |
40 | #define XDG_DBUS_PROXY_PATH "/usr/bin/xdg-dbus-proxy" | 40 | #define XDG_DBUS_PROXY_PATH "/usr/bin/xdg-dbus-proxy" |
41 | 41 | ||
42 | #define errExit(msg) do { \ | 42 | #define errExit(msg) _errExit(__FILE__, __LINE__, __func__, msg) |
43 | char msgout[500]; \ | 43 | |
44 | snprintf(msgout, 500, "Error %s:%d: %s: %s", \ | 44 | static inline void __attribute__((noreturn)) |
45 | __FILE__, __LINE__, __func__, msg); \ | 45 | _errExit(const char *fname, int lineno, const char *func, const char *msg) { |
46 | perror(msgout); \ | 46 | char msgout[500]; |
47 | exit(1); \ | 47 | snprintf(msgout, 500, "Error %s:%d: %s: %s", fname, lineno, func, msg); |
48 | } while (0) | 48 | perror(msgout); |
49 | exit(1); | ||
50 | } | ||
49 | 51 | ||
50 | // macro to print ip addresses in a printf statement | 52 | // macro to print ip addresses in a printf statement |
51 | #define PRINT_IP(A) \ | 53 | #define PRINT_IP(A) \ |