diff --git a/src/error.h b/src/error.h index daab13a..ecef253 100644 --- a/src/error.h +++ b/src/error.h @@ -3,6 +3,8 @@ #include #include +#include "util/attributes.h" + /* defines statuses in the 0..127, any higher/negative values are POSIX-reserved. * The max value (or -1) shall mean the application is running, anything else shall mean an exit code of some kind */ enum { @@ -28,10 +30,10 @@ enum { }; typedef int8_t gamestatus; -__attribute__((format(printf, 1, 2))) void debug(char const*, ...); // prints a debug message to stdout if the DEBUG environment variable is set, otherwise the call is ignored. -__attribute__((format(printf, 1, 2))) void info(char const*, ...); // prints an info message to stdout -__attribute__((format(printf, 1, 2))) void warn(char const*, ...); // prints a warning message to stderr -__attribute__((format(printf, 1, 2))) void error(char const*, ...); // prints an warning message to stderr +atrb_nonnull(1) atrb_format(printf, 1, 2) void debug(char const*, ...); // prints a debug message to stdout if the DEBUG environment variable is set, otherwise the call is ignored. +atrb_nonnull(1) atrb_format(printf, 1, 2) void info(char const*, ...); // prints an info message to stdout +atrb_nonnull(1) atrb_format(printf, 1, 2) void warn(char const*, ...); // prints a warning message to stderr +atrb_nonnull(1) atrb_format(printf, 1, 2) void error(char const*, ...); // prints an warning message to stderr // prints an error message to stderr before exiting -__attribute__((format(printf, 4, 5))) noreturn void fatal(gamestatus, char const* file_name, uint32_t line, char const* fmt, ...); +atrb_nonnull(2, 4) atrb_format(printf, 4, 5) noreturn void fatal(gamestatus, char const* file_name, uint32_t line, char const* fmt, ...); diff --git a/src/util/attributes.h b/src/util/attributes.h index 223f4fe..c187f14 100644 --- a/src/util/attributes.h +++ b/src/util/attributes.h @@ -6,6 +6,8 @@ #define atrb_unused #define atrb_pure #define atrb_const +#define atrb_format() +#define atrb_nonnull() // define the attributes where possible #if defined(__GNUC__) || defined(__clang__) @@ -25,10 +27,21 @@ # define atrb_pure __attribute__((pure)) # endif + # if __has_attribute(const) # undef atrb_const # define atrb_const __attribute__((const)) # endif + +# if __has_attribute(format) +# undef atrb_format +# define atrb_format(...) __attribute__((format(__VA_ARGS__))) +# endif + +# if __has_attribute(nonnull) +# undef atrb_nonnull +# define atrb_nonnull(...) __attribute__((nonnull(__VA_ARGS__))) +# endif #elif defined(_MSC_VER) # undef atrb_depatrb_deprecated # define atrb_deprecated __declspec(deprecated)