summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2014-08-07 03:39:13 +0200
committerHaru <haru@dotalux.com>2014-08-07 05:37:38 +0200
commitc45e3fa9793a273a0eab40d1626bcda7d710552c (patch)
tree4f6c9d47770a15c8cbfe065f7ee9203f77e57022 /src/common
parentcaf89724767465ecf339c391bb6d7a937d563fb2 (diff)
downloadhercules-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')
-rw-r--r--src/common/cbasetypes.h13
-rw-r--r--src/common/grfio.c4
-rw-r--r--src/common/malloc.c13
-rw-r--r--src/common/mapindex.c4
-rw-r--r--src/common/mutex.c8
-rw-r--r--src/common/showmsg.c25
-rw-r--r--src/common/showmsg.h38
-rw-r--r--src/common/socket.c25
-rw-r--r--src/common/sql.c45
-rw-r--r--src/common/sql.h4
-rw-r--r--src/common/strlib.c10
-rw-r--r--src/common/strlib.h4
-rw-r--r--src/common/timer.c5
-rw-r--r--src/common/utils.c16
14 files changed, 115 insertions, 99 deletions
diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h
index 6ca67382f..18bc0b8cb 100644
--- a/src/common/cbasetypes.h
+++ b/src/common/cbasetypes.h
@@ -347,6 +347,19 @@ typedef char bool;
#endif
//////////////////////////////////////////////////////////////////////////
+// Additional printf specifiers
+#if defined(_MSC_VER)
+#define PRIS_PREFIX "I"
+#else // gcc
+#define PRIS_PREFIX "z"
+#endif
+#define PRIdS PRIS_PREFIX "d"
+#define PRIxS PRIS_PREFIX "x"
+#define PRIuS PRIS_PREFIX "u"
+#define PRIXS PRIS_PREFIX "X"
+#define PRIoS PRIS_PREFIX "o"
+
+//////////////////////////////////////////////////////////////////////////
// path separator
#if defined(WIN32)
diff --git a/src/common/grfio.c b/src/common/grfio.c
index 6e628a512..5be0c8237 100644
--- a/src/common/grfio.c
+++ b/src/common/grfio.c
@@ -655,7 +655,7 @@ static bool grfio_parse_restable_row(const char* row)
char local[256];
FILELIST* entry;
- if( sscanf(row, "%[^#\r\n]#%[^#\r\n]#", w1, w2) != 2 )
+ if (sscanf(row, "%255[^#\r\n]#%255[^#\r\n]#", w1, w2) != 2)
return false;
if( strstr(w2, ".gat") == NULL && strstr(w2, ".rsw") == NULL )
@@ -805,7 +805,7 @@ void grfio_init(const char* fname)
if( line[0] == '/' && line[1] == '/' )
continue; // skip comments
- if( sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2 )
+ if (sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2) != 2)
continue; // skip unrecognized lines
// Entry table reading
diff --git a/src/common/malloc.c b/src/common/malloc.c
index 3c9fa9c54..eae9ad423 100644
--- a/src/common/malloc.c
+++ b/src/common/malloc.c
@@ -241,7 +241,7 @@ void *mmalloc_(size_t size, const char *file, int line, const char *func) {
struct unit_head *head;
if (((long) size) < 0) {
- ShowError("mmalloc_: %d\n", size);
+ ShowError("mmalloc_: %"PRIdS"\n", size);
return NULL;
}
@@ -272,7 +272,8 @@ void *mmalloc_(size_t size, const char *file, int line, const char *func) {
*(long*)((char*)p + sizeof(struct unit_head_large) - sizeof(long) + size) = 0xdeadbeaf;
return (char *)p + sizeof(struct unit_head_large) - sizeof(long);
} else {
- ShowFatalError("Memory manager::memmgr_alloc failed (allocating %d+%d bytes at %s:%d).\n", sizeof(struct unit_head_large), size, file, line);
+ ShowFatalError("Memory manager::memmgr_alloc failed (allocating %"PRIuS"+%"PRIuS" bytes at %s:%d).\n",
+ sizeof(struct unit_head_large), size, file, line);
exit(EXIT_FAILURE);
}
}
@@ -760,10 +761,10 @@ void memmgr_report (int extra) {
ShowMessage("[malloc] : reporting %u instances | %.2f MB\n",count,(double)((size)/1024)/1024);
ShowMessage("[malloc] : internal usage %.2f MB | %.2f MB\n",(double)((memmgr_usage_bytes_t-memmgr_usage_bytes)/1024)/1024,(double)((memmgr_usage_bytes_t)/1024)/1024);
- if( extra ) {
- ShowMessage("[malloc] : unit_head_large: %d bytes\n",sizeof(struct unit_head_large));
- ShowMessage("[malloc] : unit_head: %d bytes\n",sizeof(struct unit_head));
- ShowMessage("[malloc] : block: %d bytes\n",sizeof(struct block));
+ if (extra) {
+ ShowMessage("[malloc] : unit_head_large: %"PRIuS" bytes\n", sizeof(struct unit_head_large));
+ ShowMessage("[malloc] : unit_head: %"PRIuS" bytes\n", sizeof(struct unit_head));
+ ShowMessage("[malloc] : block: %"PRIuS" bytes\n", sizeof(struct block));
}
}
diff --git a/src/common/mapindex.c b/src/common/mapindex.c
index 644f2f619..f540c98d8 100644
--- a/src/common/mapindex.c
+++ b/src/common/mapindex.c
@@ -49,12 +49,12 @@ const char* mapindex_getmapname_ext(const char* string, char* output) {
size_t len;
strcpy(buf,string);
- sscanf(string,"%*[^#]%*[#]%s",buf);
+ sscanf(string, "%*[^#]%*[#]%15s", buf);
len = safestrnlen(buf, MAP_NAME_LENGTH);
if (len == MAP_NAME_LENGTH) {
- ShowWarning("(mapindex_normalize_name) Map name '%*s' is too long!\n", 2*MAP_NAME_LENGTH, buf);
+ ShowWarning("(mapindex_normalize_name) Map name '%s' is too long!\n", buf);
len--;
}
safestrncpy(dest, buf, len+1);
diff --git a/src/common/mutex.c b/src/common/mutex.c
index ea3e0f8ce..f046febf6 100644
--- a/src/common/mutex.c
+++ b/src/common/mutex.c
@@ -54,8 +54,8 @@ ramutex *ramutex_create(void) {
struct ramutex *m;
m = (struct ramutex*)aMalloc( sizeof(struct ramutex) );
- if(m == NULL){
- ShowFatalError("ramutex_create: OOM while allocating %u bytes.\n", sizeof(struct ramutex));
+ if (m == NULL) {
+ ShowFatalError("ramutex_create: OOM while allocating %"PRIuS" bytes.\n", sizeof(struct ramutex));
return NULL;
}
@@ -128,8 +128,8 @@ racond *racond_create(void) {
struct racond *c;
c = (struct racond*)aMalloc( sizeof(struct racond) );
- if(c == NULL){
- ShowFatalError("racond_create: OOM while allocating %u bytes\n", sizeof(struct racond));
+ if (c == NULL) {
+ ShowFatalError("racond_create: OOM while allocating %"PRIuS" bytes\n", sizeof(struct racond));
return NULL;
}
diff --git a/src/common/showmsg.c b/src/common/showmsg.c
index b9bcef9b2..f3982d364 100644
--- a/src/common/showmsg.c
+++ b/src/common/showmsg.c
@@ -498,8 +498,8 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr)
return 0;
}
-int FPRINTF(HANDLE handle, const char *fmt, ...)
-{
+int FPRINTF(HANDLE handle, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
+int FPRINTF(HANDLE handle, const char *fmt, ...) {
int ret;
va_list argptr;
va_start(argptr, fmt);
@@ -634,8 +634,8 @@ int VFPRINTF(FILE *file, const char *fmt, va_list argptr)
FREEBUF(tempbuf);
return 0;
}
-int FPRINTF(FILE *file, const char *fmt, ...)
-{
+int FPRINTF(FILE *file, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
+int FPRINTF(FILE *file, const char *fmt, ...) {
int ret;
va_list argptr;
va_start(argptr, fmt);
@@ -782,8 +782,8 @@ void ClearScreen(void)
ShowMessage(CL_CLS); // to prevent empty string passed messages
#endif
}
-int ShowMessage_(enum msg_type flag, const char *string, ...)
-{
+int ShowMessage_(enum msg_type flag, const char *string, ...) __attribute__((format(printf, 2, 3)));
+int ShowMessage_(enum msg_type flag, const char *string, ...) {
int ret;
va_list ap;
va_start(ap, string);
@@ -793,44 +793,50 @@ int ShowMessage_(enum msg_type flag, const char *string, ...)
}
// direct printf replacement
+void ShowMessage(const char *string, ...) __attribute__((format(printf, 1, 2)));
void ShowMessage(const char *string, ...) {
va_list ap;
va_start(ap, string);
vShowMessage_(MSG_NONE, string, ap);
va_end(ap);
}
+void ShowStatus(const char *string, ...) __attribute__((format(printf, 1, 2)));
void ShowStatus(const char *string, ...) {
va_list ap;
va_start(ap, string);
vShowMessage_(MSG_STATUS, string, ap);
va_end(ap);
}
+void ShowSQL(const char *string, ...) __attribute__((format(printf, 1, 2)));
void ShowSQL(const char *string, ...) {
va_list ap;
va_start(ap, string);
vShowMessage_(MSG_SQL, string, ap);
va_end(ap);
}
+void ShowInfo(const char *string, ...) __attribute__((format(printf, 1, 2)));
void ShowInfo(const char *string, ...) {
va_list ap;
va_start(ap, string);
vShowMessage_(MSG_INFORMATION, string, ap);
va_end(ap);
}
+void ShowNotice(const char *string, ...) __attribute__((format(printf, 1, 2)));
void ShowNotice(const char *string, ...) {
va_list ap;
va_start(ap, string);
vShowMessage_(MSG_NOTICE, string, ap);
va_end(ap);
}
+void ShowWarning(const char *string, ...) __attribute__((format(printf, 1, 2)));
void ShowWarning(const char *string, ...) {
va_list ap;
va_start(ap, string);
vShowMessage_(MSG_WARNING, string, ap);
va_end(ap);
}
-void ShowConfigWarning(config_setting_t *config, const char *string, ...)
-{
+void ShowConfigWarning(config_setting_t *config, const char *string, ...) __attribute__((format(printf, 2, 3)));
+void ShowConfigWarning(config_setting_t *config, const char *string, ...) {
StringBuf buf;
va_list ap;
StrBuf->Init(&buf);
@@ -841,18 +847,21 @@ void ShowConfigWarning(config_setting_t *config, const char *string, ...)
va_end(ap);
StrBuf->Destroy(&buf);
}
+void ShowDebug(const char *string, ...) __attribute__((format(printf, 1, 2)));
void ShowDebug(const char *string, ...) {
va_list ap;
va_start(ap, string);
vShowMessage_(MSG_DEBUG, string, ap);
va_end(ap);
}
+void ShowError(const char *string, ...) __attribute__((format(printf, 1, 2)));
void ShowError(const char *string, ...) {
va_list ap;
va_start(ap, string);
vShowMessage_(MSG_ERROR, string, ap);
va_end(ap);
}
+void ShowFatalError(const char *string, ...) __attribute__((format(printf, 1, 2)));
void ShowFatalError(const char *string, ...) {
va_list ap;
va_start(ap, string);
diff --git a/src/common/showmsg.h b/src/common/showmsg.h
index 83eb0ad89..4300c29d6 100644
--- a/src/common/showmsg.h
+++ b/src/common/showmsg.h
@@ -93,26 +93,26 @@ enum msg_type {
extern void ClearScreen(void);
#ifdef HERCULES_CORE
- extern void ShowMessage(const char *, ...);
- extern void ShowStatus(const char *, ...);
- extern void ShowSQL(const char *, ...);
- extern void ShowInfo(const char *, ...);
- extern void ShowNotice(const char *, ...);
- extern void ShowWarning(const char *, ...);
- extern void ShowDebug(const char *, ...);
- extern void ShowError(const char *, ...);
- extern void ShowFatalError(const char *, ...);
- extern void ShowConfigWarning(config_setting_t *config, const char *string, ...);
+ extern void ShowMessage(const char *, ...) __attribute__((format(printf, 1, 2)));
+ extern void ShowStatus(const char *, ...) __attribute__((format(printf, 1, 2)));
+ extern void ShowSQL(const char *, ...) __attribute__((format(printf, 1, 2)));
+ extern void ShowInfo(const char *, ...) __attribute__((format(printf, 1, 2)));
+ extern void ShowNotice(const char *, ...) __attribute__((format(printf, 1, 2)));
+ extern void ShowWarning(const char *, ...) __attribute__((format(printf, 1, 2)));
+ extern void ShowDebug(const char *, ...) __attribute__((format(printf, 1, 2)));
+ extern void ShowError(const char *, ...) __attribute__((format(printf, 1, 2)));
+ extern void ShowFatalError(const char *, ...) __attribute__((format(printf, 1, 2)));
+ extern void ShowConfigWarning(config_setting_t *config, const char *string, ...) __attribute__((format(printf, 2, 3)));
#else
- HPExport void (*ShowMessage) (const char *, ...);
- HPExport void (*ShowStatus) (const char *, ...);
- HPExport void (*ShowSQL) (const char *, ...);
- HPExport void (*ShowInfo) (const char *, ...);
- HPExport void (*ShowNotice) (const char *, ...);
- HPExport void (*ShowWarning) (const char *, ...);
- HPExport void (*ShowDebug) (const char *, ...);
- HPExport void (*ShowError) (const char *, ...);
- HPExport void (*ShowFatalError) (const char *, ...);
+ HPExport void (*ShowMessage) (const char *, ...) __attribute__((format(printf, 1, 2)));
+ HPExport void (*ShowStatus) (const char *, ...) __attribute__((format(printf, 1, 2)));
+ HPExport void (*ShowSQL) (const char *, ...) __attribute__((format(printf, 1, 2)));
+ HPExport void (*ShowInfo) (const char *, ...) __attribute__((format(printf, 1, 2)));
+ HPExport void (*ShowNotice) (const char *, ...) __attribute__((format(printf, 1, 2)));
+ HPExport void (*ShowWarning) (const char *, ...) __attribute__((format(printf, 1, 2)));
+ HPExport void (*ShowDebug) (const char *, ...) __attribute__((format(printf, 1, 2)));
+ HPExport void (*ShowError) (const char *, ...) __attribute__((format(printf, 1, 2)));
+ HPExport void (*ShowFatalError) (const char *, ...) __attribute__((format(printf, 1, 2)));
#endif
extern int vShowMessage_(enum msg_type flag, const char *string, va_list ap);
diff --git a/src/common/socket.c b/src/common/socket.c
index 85f0aa0ce..0c48c7c46 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -689,8 +689,8 @@ int RFIFOSKIP(int fd, size_t len)
s = session[fd];
- if ( s->rdata_size < s->rdata_pos + len ) {
- ShowError("RFIFOSKIP: skipped past end of read buffer! Adjusting from %d to %d (session #%d)\n", len, RFIFOREST(fd), fd);
+ if (s->rdata_size < s->rdata_pos + len) {
+ ShowError("RFIFOSKIP: skipped past end of read buffer! Adjusting from %"PRIuS" to %"PRIuS" (session #%d)\n", len, RFIFOREST(fd), fd);
len = RFIFOREST(fd);
}
@@ -738,13 +738,15 @@ int WFIFOSET(int fd, size_t len)
if( !s->flag.server ) {
- if( len > socket_max_client_packet ) {// see declaration of socket_max_client_packet for details
- ShowError("WFIFOSET: Dropped too large client packet 0x%04x (length=%u, max=%u).\n", WFIFOW(fd,0), len, socket_max_client_packet);
+ if (len > socket_max_client_packet) { // see declaration of socket_max_client_packet for details
+ ShowError("WFIFOSET: Dropped too large client packet 0x%04x (length=%"PRIuS", max=%"PRIuS").\n",
+ WFIFOW(fd,0), len, socket_max_client_packet);
return 0;
}
- if( s->wdata_size+len > WFIFO_MAX ) {// reached maximum write fifo size
- ShowError("WFIFOSET: Maximum write buffer size for client connection %d exceeded, most likely caused by packet 0x%04x (len=%u, ip=%lu.%lu.%lu.%lu).\n", fd, WFIFOW(fd,0), len, CONVIP(s->client_addr));
+ if (s->wdata_size+len > WFIFO_MAX) { // reached maximum write fifo size
+ ShowError("WFIFOSET: Maximum write buffer size for client connection %d exceeded, most likely caused by packet 0x%04x (len=%"PRIuS", ip=%u.%u.%u.%u).\n",
+ fd, WFIFOW(fd,0), len, CONVIP(s->client_addr));
set_eof(fd);
return 0;
}
@@ -1152,11 +1154,10 @@ int socket_config_read(const char* cfgName)
return 1;
}
- while(fgets(line, sizeof(line), fp))
- {
+ while (fgets(line, sizeof(line), fp)) {
if(line[0] == '/' && line[1] == '/')
continue;
- if(sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
+ if (sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2) != 2)
continue;
if (!strcmpi(w1, "stall_time")) {
@@ -1545,9 +1546,9 @@ void send_shortlist_add_fd(int fd)
if( (send_shortlist_set[i]>>bit)&1 )
return;// already in the list
- if( send_shortlist_count >= ARRAYLENGTH(send_shortlist_array) )
- {
- ShowDebug("send_shortlist_add_fd: shortlist is full, ignoring... (fd=%d shortlist.count=%d shortlist.length=%d)\n", fd, send_shortlist_count, ARRAYLENGTH(send_shortlist_array));
+ if (send_shortlist_count >= ARRAYLENGTH(send_shortlist_array)) {
+ ShowDebug("send_shortlist_add_fd: shortlist is full, ignoring... (fd=%d shortlist.count=%d shortlist.length=%"PRIuS")\n",
+ fd, send_shortlist_count, ARRAYLENGTH(send_shortlist_array));
return;
}
diff --git a/src/common/sql.c b/src/common/sql.c
index a562478ea..8ae9d3cdb 100644
--- a/src/common/sql.c
+++ b/src/common/sql.c
@@ -242,8 +242,8 @@ size_t Sql_EscapeStringLen(Sql* self, char *out_to, const char *from, size_t fro
/// Executes a query.
-int Sql_Query(Sql* self, const char* query, ...)
-{
+int Sql_Query(Sql *self, const char *query, ...) __attribute__((format(printf, 2, 3)));
+int Sql_Query(Sql *self, const char *query, ...) {
int res;
va_list args;
@@ -517,15 +517,13 @@ static int Sql_P_BindSqlDataType(MYSQL_BIND* bind, enum SqlDataType buffer_type,
/// Prints debug information about a field (type and length).
///
/// @private
-static void Sql_P_ShowDebugMysqlFieldInfo(const char* prefix, enum enum_field_types type, int is_unsigned, unsigned long length, const char* length_postfix)
-{
- const char* sign = (is_unsigned ? "UNSIGNED " : "");
- const char* type_string;
- switch( type )
- {
- default:
- ShowDebug("%stype=%s%u, length=%d\n", prefix, sign, type, length);
- return;
+static void Sql_P_ShowDebugMysqlFieldInfo(const char* prefix, enum enum_field_types type, int is_unsigned, unsigned long length, const char* length_postfix) {
+ const char *sign = (is_unsigned ? "UNSIGNED " : "");
+ const char *type_string = NULL;
+ switch (type) {
+ default:
+ ShowDebug("%stype=%s%u, length=%lu\n", prefix, sign, type, length);
+ return;
#define SHOW_DEBUG_OF(x) case x: type_string = #x; break
SHOW_DEBUG_OF(MYSQL_TYPE_TINY);
SHOW_DEBUG_OF(MYSQL_TYPE_SHORT);
@@ -548,7 +546,7 @@ static void Sql_P_ShowDebugMysqlFieldInfo(const char* prefix, enum enum_field_ty
SHOW_DEBUG_OF(MYSQL_TYPE_NULL);
#undef SHOW_DEBUG_TYPE_OF
}
- ShowDebug("%stype=%s%s, length=%d%s\n", prefix, sign, type_string, length, length_postfix);
+ ShowDebug("%stype=%s%s, length=%lu%s\n", prefix, sign, type_string, length, length_postfix);
}
@@ -607,8 +605,8 @@ SqlStmt* SqlStmt_Malloc(Sql* sql) {
/// Prepares the statement.
-int SqlStmt_Prepare(SqlStmt* self, const char* query, ...)
-{
+int SqlStmt_Prepare(SqlStmt *self, const char *query, ...) __attribute__((format(printf, 2, 3)));
+int SqlStmt_Prepare(SqlStmt *self, const char *query, ...) {
int res;
va_list args;
@@ -756,16 +754,13 @@ size_t SqlStmt_NumColumns(SqlStmt* self)
/// Binds the result of a column to a buffer.
-int SqlStmt_BindColumn(SqlStmt* self, size_t idx, enum SqlDataType buffer_type, void* buffer, size_t buffer_len, uint32* out_length, int8* out_is_null)
-{
- if( self == NULL )
+int SqlStmt_BindColumn(SqlStmt *self, size_t idx, enum SqlDataType buffer_type, void *buffer, size_t buffer_len, uint32 *out_length, int8 *out_is_null) {
+ if (self == NULL)
return SQL_ERROR;
- if( buffer_type == SQLDT_STRING || buffer_type == SQLDT_ENUM )
- {
- if( buffer_len < 1 )
- {
- ShowDebug("SqlStmt_BindColumn: buffer_len(%d) is too small, no room for the null-terminator\n", buffer_len);
+ if (buffer_type == SQLDT_STRING || buffer_type == SQLDT_ENUM) {
+ if (buffer_len < 1) {
+ ShowDebug("SqlStmt_BindColumn: buffer_len(%"PRIuS") is too small, no room for the null-terminator\n", buffer_len);
return SQL_ERROR;
}
--buffer_len;// null-terminator
@@ -974,9 +969,9 @@ void Sql_inter_server_read(const char* cfgName, bool first) {
return;
}
- while(fgets(line, sizeof(line), fp)) {
- i = sscanf(line, "%[^:]: %[^\r\n]", w1, w2);
- if(i != 2)
+ while (fgets(line, sizeof(line), fp)) {
+ i = sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2);
+ if (i != 2)
continue;
if(!strcmpi(w1,"mysql_reconnect_type")) {
diff --git a/src/common/sql.h b/src/common/sql.h
index f9593978c..b1f1f41c3 100644
--- a/src/common/sql.h
+++ b/src/common/sql.h
@@ -98,7 +98,7 @@ struct sql_interface {
/// The query is constructed as if it was sprintf.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*Query) (Sql* self, const char* query, ...);
+ int (*Query) (Sql *self, const char *query, ...) __attribute__((format(printf, 2, 3)));
/// Executes a query.
/// Any previous result is freed.
/// The query is constructed as if it was svprintf.
@@ -176,7 +176,7 @@ struct sql_interface {
/// The query is constructed as if it was sprintf.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*StmtPrepare)(SqlStmt* self, const char* query, ...);
+ int (*StmtPrepare) (SqlStmt *self, const char *query, ...) __attribute__((format(printf, 2, 3)));
/// Prepares the statement.
/// Any previous result is freed and all parameter bindings are removed.
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;
diff --git a/src/common/strlib.h b/src/common/strlib.h
index 7f84d2893..00a588772 100644
--- a/src/common/strlib.h
+++ b/src/common/strlib.h
@@ -82,7 +82,7 @@ struct strlib_interface {
/// Works like snprintf, but always null-terminates the buffer.
/// Returns the size of the string (without null-terminator)
/// 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)));
/// Returns the line of the target position in the string.
/// Lines start at 1.
@@ -99,7 +99,7 @@ struct strlib_interface *strlib;
struct stringbuf_interface {
StringBuf* (*Malloc) (void);
void (*Init) (StringBuf* self);
- int (*Printf) (StringBuf* self, const char* fmt, ...);
+ int (*Printf) (StringBuf *self, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
int (*Vprintf) (StringBuf* self, const char* fmt, va_list args);
int (*Append) (StringBuf* self, const StringBuf *sbuf);
int (*AppendStr) (StringBuf* self, const char* str);
diff --git a/src/common/timer.c b/src/common/timer.c
index 370eafd4c..5d0a45b99 100644
--- a/src/common/timer.c
+++ b/src/common/timer.c
@@ -299,8 +299,9 @@ int timer_add(int64 tick, TimerFunc func, int id, intptr_t data) {
int timer_add_interval(int64 tick, TimerFunc func, int id, intptr_t data, int interval) {
int tid;
- if( interval < 1 ) {
- ShowError("timer_add_interval: invalid interval (tick=%"PRId64" %p[%s] id=%d data=%d diff_tick=%"PRId64")\n", tick, func, search_timer_func_list(func), id, data, DIFF_TICK(tick, timer->gettick()));
+ if (interval < 1) {
+ ShowError("timer_add_interval: invalid interval (tick=%"PRId64" %p[%s] id=%d data=%"PRIdPTR" diff_tick=%"PRId64")\n",
+ tick, func, search_timer_func_list(func), id, data, DIFF_TICK(tick, timer->gettick()));
return INVALID_TIMER;
}
diff --git a/src/common/utils.c b/src/common/utils.c
index 4e6cb49c2..79232b25c 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -64,31 +64,27 @@ void WriteDump(FILE* fp, const void* buffer, size_t length)
/// Dumps given buffer on the console.
-void ShowDump(const void* buffer, size_t length)
-{
+void ShowDump(const void *buffer, size_t length) {
size_t i;
char hex[48+1], ascii[16+1];
ShowDebug("--- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F 0123456789ABCDEF\n");
ascii[16] = 0;
- for( i = 0; i < length; i++ )
- {
+ for (i = 0; i < length; i++) {
char c = RBUFB(buffer,i);
ascii[i%16] = ISCNTRL(c) ? '.' : c;
sprintf(hex+(i%16)*3, "%02X ", RBUFB(buffer,i));
- if( (i%16) == 15 )
- {
- ShowDebug("%03X %s %s\n", i/16, hex, ascii);
+ if ((i%16) == 15) {
+ ShowDebug("%03"PRIXS" %s %s\n", i/16, hex, ascii);
}
}
- if( (i%16) != 0 )
- {
+ if ((i%16) != 0) {
ascii[i%16] = 0;
- ShowDebug("%03X %-48s %-16s\n", i/16, hex, ascii);
+ ShowDebug("%03"PRIXS" %-48s %-16s\n", i/16, hex, ascii);
}
}