mirror of https://github.com/nothings/stb.git
stb_sprintf: add attribute format to variadic functions
This allows for compiler verification of the format string just like printf.
This commit is contained in:
parent
05e1efab3d
commit
40d7e47896
|
@ -7,6 +7,7 @@
|
||||||
//
|
//
|
||||||
// Contributors:
|
// Contributors:
|
||||||
// Fabian "ryg" Giesen (reformatting)
|
// Fabian "ryg" Giesen (reformatting)
|
||||||
|
// github:aganm (attribute format)
|
||||||
//
|
//
|
||||||
// Contributors (bugfixes):
|
// Contributors (bugfixes):
|
||||||
// github:d26435
|
// github:d26435
|
||||||
|
@ -176,6 +177,16 @@ PERFORMANCE vs MSVC 2008 32-/64-bit (GCC is even slower than MSVC):
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(__has_attribute)
|
||||||
|
#if __has_attribute(format)
|
||||||
|
#define STBSP__ATTRIBUTE_FORMAT(fmt,va) __attribute__((format(printf,fmt,va)))
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STBSP__ATTRIBUTE_FORMAT
|
||||||
|
#define STBSP__ATTRIBUTE_FORMAT(fmt,va)
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdarg.h> // for va_list()
|
#include <stdarg.h> // for va_list()
|
||||||
#include <stddef.h> // size_t, ptrdiff_t
|
#include <stddef.h> // size_t, ptrdiff_t
|
||||||
|
|
||||||
|
@ -190,8 +201,8 @@ typedef char *STBSP_SPRINTFCB(const char *buf, void *user, int len);
|
||||||
|
|
||||||
STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintf)(char *buf, char const *fmt, va_list va);
|
STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintf)(char *buf, char const *fmt, va_list va);
|
||||||
STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsnprintf)(char *buf, int count, char const *fmt, va_list va);
|
STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsnprintf)(char *buf, int count, char const *fmt, va_list va);
|
||||||
STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(sprintf)(char *buf, char const *fmt, ...);
|
STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(sprintf)(char *buf, char const *fmt, ...) STBSP__ATTRIBUTE_FORMAT(2,3);
|
||||||
STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(snprintf)(char *buf, int count, char const *fmt, ...);
|
STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(snprintf)(char *buf, int count, char const *fmt, ...) STBSP__ATTRIBUTE_FORMAT(3,4);
|
||||||
|
|
||||||
STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, void *user, char *buf, char const *fmt, va_list va);
|
STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, void *user, char *buf, char const *fmt, va_list va);
|
||||||
STBSP__PUBLICDEF void STB_SPRINTF_DECORATE(set_separators)(char comma, char period);
|
STBSP__PUBLICDEF void STB_SPRINTF_DECORATE(set_separators)(char comma, char period);
|
||||||
|
|
Loading…
Reference in New Issue