diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/localconsts.h | 49 | ||||
-rw-r--r-- | src/logger.h | 6 | ||||
-rw-r--r-- | src/utils/stringutils.h | 13 | ||||
-rw-r--r-- | src/utils/xml/libxml.cpp | 9 |
4 files changed, 36 insertions, 41 deletions
diff --git a/src/localconsts.h b/src/localconsts.h index 6a50a789f..fe53c590c 100644 --- a/src/localconsts.h +++ b/src/localconsts.h @@ -171,30 +171,37 @@ #define gnu_printf printf #endif // __clang__ +/* + * A_FORMAT_PRINTF: Proxy for printf-like attribute tagging, + * All argument positions start indexed by 1 + * + * isMember true if member function. The below will shift by one. + * fmtIndex: position of format string in argument list + * firstArgIndex: position of first optional argument to format. + */ +#ifdef BAD_CILKPLUS +#define A_FORMAT_PRINTF_SHIFT 0 +#else +#define A_FORMAT_PRINTF_SHIFT 1 +#endif +// idk how to clean this up #ifdef __GNUC__ #ifdef __OpenBSD__ - #define A_FORMAT_PRINTF(fmtIndex, firstArgIndex) \ - __attribute__((__format__(printf, (fmtIndex), (firstArgIndex)))) - #else // __OpenBSD__ - - #ifdef BAD_CILKPLUS - // This one is 0-indexed? - #define A_FORMAT_PRINTF(fmtIndex, firstArgIndex) \ - __attribute__((__format__(gnu_printf, \ - ((fmtIndex) - 1), \ - ((firstArgIndex)-1) \ - ))) - #else // BAD_CILKPLUS - #define A_FORMAT_PRINTF(fmtIndex, firstArgIndex) \ - __attribute__((__format__(gnu_printf, \ - (fmtIndex), \ - (firstArgIndex) \ - ))) - #endif // BAD_CILKPLUS - - #endif // __OpenBSD__ -#endif // __GNUC__ + #define A_FORMAT_PRINTF_FUNC printf + #else + #define A_FORMAT_PRINTF_FUNC gnu_printf + #endif +#else + #define A_FORMAT_PRINTF_FUNC gnu_printf +#endif + +#define A_FORMAT_PRINTF(isMember, fmtIndex, firstArgIndex) \ + __attribute__((__format__( \ + A_FORMAT_PRINTF_FUNC, \ + ((fmtIndex) + ((isMember) ? A_FORMAT_PRINTF_SHIFT : 0)), \ + ((firstArgIndex) + ((isMember) ? A_FORMAT_PRINTF_SHIFT : 0)) \ + ))) #ifdef ADVGCC diff --git a/src/logger.h b/src/logger.h index 89f4c5286..da165189d 100644 --- a/src/logger.h +++ b/src/logger.h @@ -93,21 +93,21 @@ class Logger final */ void log(const char *const log_text, ...) A_NONNULL(2) - A_FORMAT_PRINTF(2, 3); + A_FORMAT_PRINTF(true, 1, 2); /** * Enters a message in the log. The message will be timestamped. */ void assertLog(const char *const log_text, ...) A_NONNULL(2) - A_FORMAT_PRINTF(2, 3); + A_FORMAT_PRINTF(true, 1, 2); /** * Enters a message in the log (thread safe). */ void log_r(const char *const log_text, ...) A_NONNULL(2) - A_FORMAT_PRINTF(2, 3); + A_FORMAT_PRINTF(true, 1, 2); /** * Enters a message in the log. The message will be timestamped. diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index b5eca16ab..6d33c3830 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -100,15 +100,10 @@ const char *ipToString(const uint32_t address) A_WARN_UNUSED; /** * A safe version of sprintf that returns a std::string of the result. */ -std::string strprintf(const char *const format, ...) A_NONNULL(1) A_WARN_UNUSED -#ifdef __GNUC__ -#ifdef __OpenBSD__ - __attribute__((__format__(printf, 1, 2))) -#else // __OpenBSD__ - __attribute__((__format__(gnu_printf, 1, 2))) -#endif // __OpenBSD__ -#endif // __GNUC__ -; +std::string strprintf(const char *const format, ...) + A_NONNULL(1) + A_WARN_UNUSED + A_FORMAT_PRINTF(false, 1, 2); /** * Removes colors from a string diff --git a/src/utils/xml/libxml.cpp b/src/utils/xml/libxml.cpp index cc49a6012..97d2db58c 100644 --- a/src/utils/xml/libxml.cpp +++ b/src/utils/xml/libxml.cpp @@ -44,14 +44,7 @@ namespace } // namespace static void xmlErrorLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...) -#ifdef __GNUC__ -#ifdef __OpenBSD__ - __attribute__((__format__(printf, 2, 3))) -#else // __OpenBSD__ - __attribute__((__format__(gnu_printf, 2, 3))) -#endif // __OpenBSD__ -#endif // __GNUC__ -; + A_FORMAT_PRINTF(false, 2, 3); static void xmlErrorLogger(void *ctx A_UNUSED, const char *msg, ...) { |