foxygit / doom Log in
commit 14e9e565715db5e1d1fc92aa4f3d31b488b00112
Author:     Turo Lamminen <turotl@gmail.com>
AuthorDate: Sat Feb 17 16:15:13 2018 +0200
Commit:     Turo Lamminen <turotl@gmail.com>
CommitDate: Sat Feb 17 16:15:13 2018 +0200

    Add format string attribute to TXT_snprintf
---
 textscreen/txt_main.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/textscreen/txt_main.h b/textscreen/txt_main.h
index 1565f0bf..3cc78b30 100644
--- a/textscreen/txt_main.h
+++ b/textscreen/txt_main.h
@@ -122,6 +122,17 @@ typedef enum
     TXT_INPUT_TEXT,
 } txt_input_mode_t;

+
+#ifdef __GNUC__
+
+#define PRINTF_ATTR(fmt, first) __attribute__((format(printf, fmt, first)))
+
+#else  // __GNUC__
+
+#define PRINTF_ATTR(fmt, first)
+
+#endif  // __GNUC__
+
 // Initialize the screen
 // Returns 1 if successful, 0 if failed.
 int TXT_Init(void);
@@ -181,7 +192,7 @@ void TXT_StringConcat(char *dest, const char *src, size_t dest_len);
 int TXT_vsnprintf(char *buf, size_t buf_len, const char *s, va_list args);

 // Safe version of snprintf().
-int TXT_snprintf(char *buf, size_t buf_len, const char *s, ...);
+int TXT_snprintf(char *buf, size_t buf_len, const char *s, ...) PRINTF_ATTR(3, 4);

 #endif /* #ifndef TXT_MAIN_H */