mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-23 00:01:16 -03:00
implement our own assert() function
I recently upgraded the software on my macOS server and was dismayed to see that cppcheck reported a huge number of format string errors due to mismatches between the format string and its arguments from calls to `assert()`. It turns out they are due to the macOS header using `%lu` for the line number which is obviously wrong since it is using the C preprocessor `__LINE__` symbol which evaluates to a signed int. I also noticed that the macOS implementation writes to stdout, rather than stderr. It also uses `printf()` which can be a problem on some platforms if the stream is already in wide mode which is the normal case for fish. So implement our own `assert()` implementation. This also eliminates double-negative warnings that we get from some of our calls to `assert()` on some platforms by oclint. Also reimplement the `DIE()` macro in terms of our internal implementation. Rewrite `assert(0 && msg)` statements to `DIE(msg)` for clarity and to eliminate oclint warnings about constant expressions. Fixes #3276, albeit not in the fashion I originally envisioned.
This commit is contained in:
@@ -2,16 +2,15 @@
|
||||
#include "config.h" // IWYU pragma: keep
|
||||
|
||||
#include <arpa/inet.h> // IWYU pragma: keep
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
// We need the sys/file.h for the flock() declaration on Linux but not OS X.
|
||||
#include <sys/file.h> // IWYU pragma: keep
|
||||
// We need the ioctl.h header so we can check if SIOCGIFHWADDR is defined by it so we know if we're
|
||||
// on a Linux system.
|
||||
#include <sys/ioctl.h> // IWYU pragma: keep
|
||||
#include <limits.h>
|
||||
#include <netinet/in.h> // IWYU pragma: keep
|
||||
#include <sys/ioctl.h> // IWYU pragma: keep
|
||||
#if !defined(__APPLE__) && !defined(__CYGWIN__)
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
@@ -26,7 +25,7 @@
|
||||
#include <sys/select.h> // IWYU pragma: keep
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h> // IWYU pragma: keep
|
||||
#include <sys/time.h> // IWYU pragma: keep
|
||||
#include <sys/types.h> // IWYU pragma: keep
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
|
||||
Reference in New Issue
Block a user