Fixed printf issues with size_t. Since Windows do not support %zu we have to use %Iu there instead.

Solved that with an ugly but needed macro.
This commit is contained in:
Jan Vidar Krey 2009-08-20 10:44:44 +02:00
parent 5bd258ca52
commit 1af613d9ce
4 changed files with 20 additions and 12 deletions

View File

@ -169,7 +169,7 @@ static int command_status(struct hub_info* hub, struct hub_user* user, struct hu
static int command_stats(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd) static int command_stats(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd)
{ {
char temp[128]; char temp[128];
snprintf(temp, 128, "%zu users, peak: %zu. Network (up/down): %d/%d KB/s, peak: %d/%d KB/s", snprintf(temp, 128, PRINTF_SIZE_T " users, peak: " PRINTF_SIZE_T ". Network (up/down): %d/%d KB/s, peak: %d/%d KB/s",
hub->users->count, hub->users->count,
hub->users->count_peak, hub->users->count_peak,
(int) hub->stats.net_tx / 1024, (int) hub->stats.net_tx / 1024,
@ -330,7 +330,7 @@ static int command_whoip(struct hub_info* hub, struct hub_user* user, struct hub
} }
char tmp[128]; char tmp[128];
snprintf(tmp, 128, "*** %s: Found %d match%s:", cmd->prefix, (int) ret, ((ret != 1) ? "es" : "")); snprintf(tmp, 128, "*** %s: Found %d match%s:", cmd->prefix, ret, ((ret != 1) ? "es" : ""));
char* buffer = hub_malloc(((MAX_NICK_LEN + INET6_ADDRSTRLEN + 5) * ret) + strlen(tmp) + 3); char* buffer = hub_malloc(((MAX_NICK_LEN + INET6_ADDRSTRLEN + 5) * ret) + strlen(tmp) + 3);
buffer[0] = 0; buffer[0] = 0;
@ -376,7 +376,7 @@ static int command_history(struct hub_info* hub, struct hub_user* user, struct h
} }
char tmp[128]; char tmp[128];
snprintf(tmp, 128, "*** %s: Found %d message%s:", cmd->prefix, (int) ret, ((ret != 1) ? "s" : "")); snprintf(tmp, 128, "*** %s: Found %d message%s:", cmd->prefix, ret, ((ret != 1) ? "s" : ""));
bufsize = strlen(tmp); bufsize = strlen(tmp);
message = (char*) list_get_first(messages); message = (char*) list_get_first(messages);
while (message) while (message)
@ -430,11 +430,11 @@ static int command_log(struct hub_info* hub, struct hub_user* user, struct hub_c
if (search_len) if (search_len)
{ {
sprintf(tmp, "Logged entries: %d, searching for \"%s\"", (int) list_size(messages), search); sprintf(tmp, "Logged entries: " PRINTF_SIZE_T ", searching for \"%s\"", list_size(messages), search);
} }
else else
{ {
sprintf(tmp, "Logged entries: %d", (int) list_size(messages)); sprintf(tmp, "Logged entries: " PRINTF_SIZE_T, list_size(messages));
} }
command_status(hub, user, cmd, tmp); command_status(hub, user, cmd, tmp);
@ -467,7 +467,7 @@ static int command_log(struct hub_info* hub, struct hub_user* user, struct hub_c
if (search_len) if (search_len)
{ {
sprintf(tmp, "%d entries shown.", (int) search_hits); sprintf(tmp, PRINTF_SIZE_T " entries shown.", search_hits);
command_status(hub, user, cmd, tmp); command_status(hub, user, cmd, tmp);
} }

View File

@ -61,7 +61,7 @@ void uman_update_stats(struct hub_info* hub)
void uman_print_stats(struct hub_info* hub) void uman_print_stats(struct hub_info* hub)
{ {
LOG_INFO("Statistics users=%zu (peak_users=%zu), net_tx=%d KB/s, net_rx=%d KB/s (peak_tx=%d KB/s, peak_rx=%d KB/s)", LOG_INFO("Statistics users=" PRINTF_SIZE_T " (peak_users=" PRINTF_SIZE_T "), net_tx=%d KB/s, net_rx=%d KB/s (peak_tx=%d KB/s, peak_rx=%d KB/s)",
hub->users->count, hub->users->count,
hub->users->count_peak, hub->users->count_peak,
(int) hub->stats.net_tx / 1024, (int) hub->stats.net_tx / 1024,

View File

@ -89,6 +89,14 @@
#define HAVE_GETRLIMIT #define HAVE_GETRLIMIT
#endif #endif
/* printf and size_t support */
#if defined(WIN32)
/* Windows uses %Iu for size_t */
#define PRINTF_SIZE_T "%Iu"
#else
#define PRINTF_SIZE_T "%zu"
#endif
#ifdef SSL_SUPPORT #ifdef SSL_SUPPORT
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <openssl/err.h> #include <openssl/err.h>

View File

@ -47,7 +47,7 @@ void internal_debug_print_leaks()
size_t n = 0; size_t n = 0;
size_t leak = 0; size_t leak = 0;
size_t count = 0; size_t count = 0;
LOG_MEMORY("--- exit (allocs: %d, size: %zu) ---", hub_alloc_count, hub_alloc_size); LOG_MEMORY("--- exit (allocs: %d, size: " PRINTF_SIZE_T ") ---", hub_alloc_count, hub_alloc_size);
for (; n < UHUB_MAX_ALLOCS; n++) for (; n < UHUB_MAX_ALLOCS; n++)
{ {
@ -55,11 +55,11 @@ void internal_debug_print_leaks()
{ {
leak += hub_allocs[n].size; leak += hub_allocs[n].size;
count++; count++;
LOG_MEMORY("leak %p size: %zu (bt: %p %p)", hub_allocs[n].ptr, hub_allocs[n].size, hub_allocs[n].stack1, hub_allocs[n].stack2); LOG_MEMORY("leak %p size: " PRINTF_SIZE_T " (bt: %p %p)", hub_allocs[n].ptr, hub_allocs[n].size, hub_allocs[n].stack1, hub_allocs[n].stack2);
} }
} }
LOG_MEMORY("--- done (allocs: %d, size: %zu, peak: %d/%zu, oom: %zu) ---", count, leak, hub_alloc_peak_count, hub_alloc_peak_size, hub_alloc_oom); LOG_MEMORY("--- done (allocs: %d, size: " PRINTF_SIZE_T ", peak: %d/" PRINTF_SIZE_T ", oom: " PRINTF_SIZE_T ") ---", count, leak, hub_alloc_peak_count, hub_alloc_peak_size, hub_alloc_oom);
} }
#endif /* REALTIME_MALLOC_TRACKING */ #endif /* REALTIME_MALLOC_TRACKING */
@ -107,7 +107,7 @@ void* internal_debug_mem_malloc(size_t size, const char* where)
hub_alloc_peak_count = MAX(hub_alloc_count, hub_alloc_peak_count); hub_alloc_peak_count = MAX(hub_alloc_count, hub_alloc_peak_count);
hub_alloc_peak_size = MAX(hub_alloc_size, hub_alloc_peak_size); hub_alloc_peak_size = MAX(hub_alloc_size, hub_alloc_peak_size);
LOG_MEMORY("%s %p (%d bytes) (bt: %p %p) {allocs: %d, size: %zu}", where, ptr, (int) size, hub_allocs[n].stack1, hub_allocs[n].stack2, hub_alloc_count, hub_alloc_size); LOG_MEMORY("%s %p (%d bytes) (bt: %p %p) {allocs: %d, size: " PRINTF_SIZE_T "}", where, ptr, (int) size, hub_allocs[n].stack1, hub_allocs[n].stack2, hub_alloc_count, hub_alloc_size);
break; break;
} }
} }
@ -141,7 +141,7 @@ void internal_debug_mem_free(void* ptr)
hub_allocs[n].size = 0; hub_allocs[n].size = 0;
hub_allocs[n].stack1 = 0; hub_allocs[n].stack1 = 0;
hub_allocs[n].stack2 = 0; hub_allocs[n].stack2 = 0;
LOG_MEMORY("free %p (bt: %p %p) {allocs: %d, size: %zu}", ptr, stack1, stack2, hub_alloc_count, hub_alloc_size); LOG_MEMORY("free %p (bt: %p %p) {allocs: %d, size: " PRINTF_SIZE_T "}", ptr, stack1, stack2, hub_alloc_count, hub_alloc_size);
malloc_slot = n; malloc_slot = n;
free(ptr); free(ptr);
return; return;