summaryrefslogtreecommitdiff
path: root/src/stdafx.h
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-05-10 17:27:25 +0000
committersmatz <smatz@openttd.org>2009-05-10 17:27:25 +0000
commitf5316c5cbd13c3ce8c0a7d8b652ce7d975c17438 (patch)
treee9c57e3fa45a652740e681f7d25b731d7b2f9cfb /src/stdafx.h
parent552f10bb09667a7c36724092d290808c2c9e51b4 (diff)
downloadopenttd-f5316c5cbd13c3ce8c0a7d8b652ce7d975c17438.tar.xz
(svn r16269) -Codechange: use gcc's ability to check parameters sent to printf-like functions
-Fix: wrong number of parameters or wrong parameter types sent to printf-like functions at several places
Diffstat (limited to 'src/stdafx.h')
-rw-r--r--src/stdafx.h22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/stdafx.h b/src/stdafx.h
index 9e0692f46..d6b735cd9 100644
--- a/src/stdafx.h
+++ b/src/stdafx.h
@@ -126,6 +126,9 @@
#define CDECL
#define __int64 long long
#define GCC_PACK __attribute__((packed))
+ /* Warn about functions using 'printf' format syntax. First argument determines which parameter
+ * is the format string, second argument is start of values passed to printf. */
+ #define WARN_FORMAT(string, args) __attribute__ ((format (printf, string, args)))
#if (__GNUC__ == 2)
#undef VARARRAY_SIZE
@@ -138,6 +141,7 @@
#define FORCEINLINE inline
#define CDECL
#define GCC_PACK
+ #define WARN_FORMAT(string, args)
#include <malloc.h>
#endif /* __WATCOMC__ */
@@ -177,6 +181,7 @@
#pragma warning(disable: 6031) // code analyzer: Return value ignored: 'ReadFile'
#pragma warning(disable: 6255) // code analyzer: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead
#pragma warning(disable: 6246) // code analyzer: Local declaration of 'statspec' hides declaration of the same name in outer scope. For additional information, see previous declaration at ...
+ #define WARN_FORMAT(string, args)
#include <malloc.h> // alloca()
#define NORETURN __declspec(noreturn)
@@ -187,7 +192,7 @@
#define CDECL _cdecl
#endif
- int CDECL snprintf(char *str, size_t size, const char *format, ...);
+ int CDECL snprintf(char *str, size_t size, const char *format, ...) WARN_FORMAT(3, 4);
#if defined(WINCE)
int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap);
#endif
@@ -224,7 +229,7 @@
#define strncasecmp strnicmp
#endif
- void SetExceptionString(const char *s, ...);
+ void SetExceptionString(const char *s, ...) WARN_FORMAT(1, 2);
#if defined(NDEBUG) && defined(WITH_ASSERT)
#undef assert
@@ -272,6 +277,15 @@
#define PATHSEPCHAR '/'
#endif
+/* MSVCRT of course has to have a different syntax for long long *sigh* */
+#if defined(_MSC_VER) || defined(__MINGW32__)
+ #define OTTD_PRINTF64 "%I64d"
+ #define PRINTF_SIZE "%Iu"
+#else
+ #define OTTD_PRINTF64 "%lld"
+ #define PRINTF_SIZE "%zu"
+#endif
+
typedef unsigned char byte;
/* This is already defined in unix, but not in QNX Neutrino (6.x)*/
@@ -346,8 +360,8 @@ assert_compile(sizeof(uint8) == 1);
#define CloseConnection OTTD_CloseConnection
#endif /* __APPLE__ */
-void NORETURN CDECL usererror(const char *str, ...);
-void NORETURN CDECL error(const char *str, ...);
+void NORETURN CDECL usererror(const char *str, ...) WARN_FORMAT(1, 2);
+void NORETURN CDECL error(const char *str, ...) WARN_FORMAT(1, 2);
#define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
#if defined(MORPHOS) || defined(__NDS__) || defined(__DJGPP__)