diff options
author | Haru <haru@dotalux.com> | 2014-08-07 03:39:13 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2014-08-07 05:37:38 +0200 |
commit | c45e3fa9793a273a0eab40d1626bcda7d710552c (patch) | |
tree | 4f6c9d47770a15c8cbfe065f7ee9203f77e57022 /src/common/strlib.c | |
parent | caf89724767465ecf339c391bb6d7a937d563fb2 (diff) | |
download | hercules-c45e3fa9793a273a0eab40d1626bcda7d710552c.tar.gz hercules-c45e3fa9793a273a0eab40d1626bcda7d710552c.tar.bz2 hercules-c45e3fa9793a273a0eab40d1626bcda7d710552c.tar.xz hercules-c45e3fa9793a273a0eab40d1626bcda7d710552c.zip |
Corrected several format-string errors through the code
- Functions that expect a printf-style format string are now marked as
such, so that gcc/clang will emit a warning warn you if you mismatch
format string and arguments.
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common/strlib.c')
-rw-r--r-- | src/common/strlib.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/common/strlib.c b/src/common/strlib.c index e2382e6fc..592390770 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -394,16 +394,15 @@ size_t safestrnlen(const char* string, size_t maxlen) /// @param fmt Format string /// @param ... Format arguments /// @return The size of the string or -1 if the buffer is too small -int safesnprintf(char* buf, size_t sz, const char* fmt, ...) -{ +int safesnprintf(char *buf, size_t sz, const char *fmt, ...) __attribute__((format(printf, 3, 4))); +int safesnprintf(char *buf, size_t sz, const char *fmt, ...) { va_list ap; int ret; va_start(ap,fmt); ret = vsnprintf(buf, sz, fmt, ap); va_end(ap); - if( ret < 0 || (size_t)ret >= sz ) - {// overflow + if (ret < 0 || (size_t)ret >= sz) { // overflow buf[sz-1] = '\0';// always null-terminate return -1; } @@ -1020,7 +1019,8 @@ void StringBuf_Init(StringBuf* self) { } /// Appends the result of printf to the StringBuf -int StringBuf_Printf(StringBuf* self, const char* fmt, ...) { +int StringBuf_Printf(StringBuf *self, const char *fmt, ...) __attribute__((format(printf, 2, 3))); +int StringBuf_Printf(StringBuf *self, const char *fmt, ...) { int len; va_list ap; |