From d2a37badc2660bfe449a55d62b98a00532d4e299 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 27 Feb 2013 12:27:15 +0100 Subject: [PATCH] Use GCC printf format attribute for redisLog(). This commit also fixes redisLog() statements producing warnings. --- src/aof.c | 2 +- src/debug.c | 155 +++++++++++++++++++++++----------------------- src/redis.c | 4 +- src/redis.h | 5 ++ src/replication.c | 7 ++- 5 files changed, 91 insertions(+), 82 deletions(-) diff --git a/src/aof.c b/src/aof.c index c4526501..c629bed4 100644 --- a/src/aof.c +++ b/src/aof.c @@ -536,7 +536,7 @@ int loadAppendOnlyFile(char *filename) { /* Command lookup */ cmd = lookupCommand(argv[0]->ptr); if (!cmd) { - redisLog(REDIS_WARNING,"Unknown command '%s' reading the append only file", argv[0]->ptr); + redisLog(REDIS_WARNING,"Unknown command '%s' reading the append only file", (char*)argv[0]->ptr); exit(1); } /* Run the command in the context of a fake client */ diff --git a/src/debug.c b/src/debug.c index 65174af9..b7127979 100644 --- a/src/debug.c +++ b/src/debug.c @@ -384,7 +384,7 @@ void redisLogObjectDebugInfo(robj *o) { redisLog(REDIS_WARNING,"Object encoding: %d", o->encoding); redisLog(REDIS_WARNING,"Object refcount: %d", o->refcount); if (o->type == REDIS_STRING && o->encoding == REDIS_ENCODING_RAW) { - redisLog(REDIS_WARNING,"Object raw string len: %d", sdslen(o->ptr)); + redisLog(REDIS_WARNING,"Object raw string len: %zu", sdslen(o->ptr)); if (sdslen(o->ptr) < 4096) redisLog(REDIS_WARNING,"Object raw string content: \"%s\"", (char*)o->ptr); } else if (o->type == REDIS_LIST) { @@ -467,10 +467,13 @@ static void *getMcontextEip(ucontext_t *uc) { void logStackContent(void **sp) { int i; for (i = 15; i >= 0; i--) { + unsigned long addr = (unsigned long) sp+i; + unsigned long val = (unsigned long) sp[i]; + if (sizeof(long) == 4) - redisLog(REDIS_WARNING, "(%08lx) -> %08lx", sp+i, sp[i]); + redisLog(REDIS_WARNING, "(%08lx) -> %08lx", addr, val); else - redisLog(REDIS_WARNING, "(%016lx) -> %016lx", sp+i, sp[i]); + redisLog(REDIS_WARNING, "(%016lx) -> %016lx", addr, val); } } @@ -488,27 +491,27 @@ void logRegisters(ucontext_t *uc) { "R8 :%016lx R9 :%016lx\nR10:%016lx R11:%016lx\n" "R12:%016lx R13:%016lx\nR14:%016lx R15:%016lx\n" "RIP:%016lx EFL:%016lx\nCS :%016lx FS:%016lx GS:%016lx", - uc->uc_mcontext->__ss.__rax, - uc->uc_mcontext->__ss.__rbx, - uc->uc_mcontext->__ss.__rcx, - uc->uc_mcontext->__ss.__rdx, - uc->uc_mcontext->__ss.__rdi, - uc->uc_mcontext->__ss.__rsi, - uc->uc_mcontext->__ss.__rbp, - uc->uc_mcontext->__ss.__rsp, - uc->uc_mcontext->__ss.__r8, - uc->uc_mcontext->__ss.__r9, - uc->uc_mcontext->__ss.__r10, - uc->uc_mcontext->__ss.__r11, - uc->uc_mcontext->__ss.__r12, - uc->uc_mcontext->__ss.__r13, - uc->uc_mcontext->__ss.__r14, - uc->uc_mcontext->__ss.__r15, - uc->uc_mcontext->__ss.__rip, - uc->uc_mcontext->__ss.__rflags, - uc->uc_mcontext->__ss.__cs, - uc->uc_mcontext->__ss.__fs, - uc->uc_mcontext->__ss.__gs + (unsigned long) uc->uc_mcontext->__ss.__rax, + (unsigned long) uc->uc_mcontext->__ss.__rbx, + (unsigned long) uc->uc_mcontext->__ss.__rcx, + (unsigned long) uc->uc_mcontext->__ss.__rdx, + (unsigned long) uc->uc_mcontext->__ss.__rdi, + (unsigned long) uc->uc_mcontext->__ss.__rsi, + (unsigned long) uc->uc_mcontext->__ss.__rbp, + (unsigned long) uc->uc_mcontext->__ss.__rsp, + (unsigned long) uc->uc_mcontext->__ss.__r8, + (unsigned long) uc->uc_mcontext->__ss.__r9, + (unsigned long) uc->uc_mcontext->__ss.__r10, + (unsigned long) uc->uc_mcontext->__ss.__r11, + (unsigned long) uc->uc_mcontext->__ss.__r12, + (unsigned long) uc->uc_mcontext->__ss.__r13, + (unsigned long) uc->uc_mcontext->__ss.__r14, + (unsigned long) uc->uc_mcontext->__ss.__r15, + (unsigned long) uc->uc_mcontext->__ss.__rip, + (unsigned long) uc->uc_mcontext->__ss.__rflags, + (unsigned long) uc->uc_mcontext->__ss.__cs, + (unsigned long) uc->uc_mcontext->__ss.__fs, + (unsigned long) uc->uc_mcontext->__ss.__gs ); logStackContent((void**)uc->uc_mcontext->__ss.__rsp); #else @@ -519,22 +522,22 @@ void logRegisters(ucontext_t *uc) { "EDI:%08lx ESI:%08lx EBP:%08lx ESP:%08lx\n" "SS:%08lx EFL:%08lx EIP:%08lx CS :%08lx\n" "DS:%08lx ES:%08lx FS :%08lx GS :%08lx", - uc->uc_mcontext->__ss.__eax, - uc->uc_mcontext->__ss.__ebx, - uc->uc_mcontext->__ss.__ecx, - uc->uc_mcontext->__ss.__edx, - uc->uc_mcontext->__ss.__edi, - uc->uc_mcontext->__ss.__esi, - uc->uc_mcontext->__ss.__ebp, - uc->uc_mcontext->__ss.__esp, - uc->uc_mcontext->__ss.__ss, - uc->uc_mcontext->__ss.__eflags, - uc->uc_mcontext->__ss.__eip, - uc->uc_mcontext->__ss.__cs, - uc->uc_mcontext->__ss.__ds, - uc->uc_mcontext->__ss.__es, - uc->uc_mcontext->__ss.__fs, - uc->uc_mcontext->__ss.__gs + (unsigned long) uc->uc_mcontext->__ss.__eax, + (unsigned long) uc->uc_mcontext->__ss.__ebx, + (unsigned long) uc->uc_mcontext->__ss.__ecx, + (unsigned long) uc->uc_mcontext->__ss.__edx, + (unsigned long) uc->uc_mcontext->__ss.__edi, + (unsigned long) uc->uc_mcontext->__ss.__esi, + (unsigned long) uc->uc_mcontext->__ss.__ebp, + (unsigned long) uc->uc_mcontext->__ss.__esp, + (unsigned long) uc->uc_mcontext->__ss.__ss, + (unsigned long) uc->uc_mcontext->__ss.__eflags, + (unsigned long) uc->uc_mcontext->__ss.__eip, + (unsigned long) uc->uc_mcontext->__ss.__cs, + (unsigned long) uc->uc_mcontext->__ss.__ds, + (unsigned long) uc->uc_mcontext->__ss.__es, + (unsigned long) uc->uc_mcontext->__ss.__fs, + (unsigned long) uc->uc_mcontext->__ss.__gs ); logStackContent((void**)uc->uc_mcontext->__ss.__esp); #endif @@ -548,22 +551,22 @@ void logRegisters(ucontext_t *uc) { "EDI:%08lx ESI:%08lx EBP:%08lx ESP:%08lx\n" "SS :%08lx EFL:%08lx EIP:%08lx CS:%08lx\n" "DS :%08lx ES :%08lx FS :%08lx GS:%08lx", - uc->uc_mcontext.gregs[11], - uc->uc_mcontext.gregs[8], - uc->uc_mcontext.gregs[10], - uc->uc_mcontext.gregs[9], - uc->uc_mcontext.gregs[4], - uc->uc_mcontext.gregs[5], - uc->uc_mcontext.gregs[6], - uc->uc_mcontext.gregs[7], - uc->uc_mcontext.gregs[18], - uc->uc_mcontext.gregs[17], - uc->uc_mcontext.gregs[14], - uc->uc_mcontext.gregs[15], - uc->uc_mcontext.gregs[3], - uc->uc_mcontext.gregs[2], - uc->uc_mcontext.gregs[1], - uc->uc_mcontext.gregs[0] + (unsigned long) uc->uc_mcontext.gregs[11], + (unsigned long) uc->uc_mcontext.gregs[8], + (unsigned long) uc->uc_mcontext.gregs[10], + (unsigned long) uc->uc_mcontext.gregs[9], + (unsigned long) uc->uc_mcontext.gregs[4], + (unsigned long) uc->uc_mcontext.gregs[5], + (unsigned long) uc->uc_mcontext.gregs[6], + (unsigned long) uc->uc_mcontext.gregs[7], + (unsigned long) uc->uc_mcontext.gregs[18], + (unsigned long) uc->uc_mcontext.gregs[17], + (unsigned long) uc->uc_mcontext.gregs[14], + (unsigned long) uc->uc_mcontext.gregs[15], + (unsigned long) uc->uc_mcontext.gregs[3], + (unsigned long) uc->uc_mcontext.gregs[2], + (unsigned long) uc->uc_mcontext.gregs[1], + (unsigned long) uc->uc_mcontext.gregs[0] ); logStackContent((void**)uc->uc_mcontext.gregs[7]); #elif defined(__X86_64__) || defined(__x86_64__) @@ -575,25 +578,25 @@ void logRegisters(ucontext_t *uc) { "R8 :%016lx R9 :%016lx\nR10:%016lx R11:%016lx\n" "R12:%016lx R13:%016lx\nR14:%016lx R15:%016lx\n" "RIP:%016lx EFL:%016lx\nCSGSFS:%016lx", - uc->uc_mcontext.gregs[13], - uc->uc_mcontext.gregs[11], - uc->uc_mcontext.gregs[14], - uc->uc_mcontext.gregs[12], - uc->uc_mcontext.gregs[8], - uc->uc_mcontext.gregs[9], - uc->uc_mcontext.gregs[10], - uc->uc_mcontext.gregs[15], - uc->uc_mcontext.gregs[0], - uc->uc_mcontext.gregs[1], - uc->uc_mcontext.gregs[2], - uc->uc_mcontext.gregs[3], - uc->uc_mcontext.gregs[4], - uc->uc_mcontext.gregs[5], - uc->uc_mcontext.gregs[6], - uc->uc_mcontext.gregs[7], - uc->uc_mcontext.gregs[16], - uc->uc_mcontext.gregs[17], - uc->uc_mcontext.gregs[18] + (unsigned long) uc->uc_mcontext.gregs[13], + (unsigned long) uc->uc_mcontext.gregs[11], + (unsigned long) uc->uc_mcontext.gregs[14], + (unsigned long) uc->uc_mcontext.gregs[12], + (unsigned long) uc->uc_mcontext.gregs[8], + (unsigned long) uc->uc_mcontext.gregs[9], + (unsigned long) uc->uc_mcontext.gregs[10], + (unsigned long) uc->uc_mcontext.gregs[15], + (unsigned long) uc->uc_mcontext.gregs[0], + (unsigned long) uc->uc_mcontext.gregs[1], + (unsigned long) uc->uc_mcontext.gregs[2], + (unsigned long) uc->uc_mcontext.gregs[3], + (unsigned long) uc->uc_mcontext.gregs[4], + (unsigned long) uc->uc_mcontext.gregs[5], + (unsigned long) uc->uc_mcontext.gregs[6], + (unsigned long) uc->uc_mcontext.gregs[7], + (unsigned long) uc->uc_mcontext.gregs[16], + (unsigned long) uc->uc_mcontext.gregs[17], + (unsigned long) uc->uc_mcontext.gregs[18] ); logStackContent((void**)uc->uc_mcontext.gregs[15]); #endif @@ -660,7 +663,7 @@ void logCurrentClient(void) { de = dictFind(cc->db->dict, key->ptr); if (de) { val = dictGetVal(de); - redisLog(REDIS_WARNING,"key '%s' found in DB containing the following object:", key->ptr); + redisLog(REDIS_WARNING,"key '%s' found in DB containing the following object:", (char*)key->ptr); redisLogObjectDebugInfo(val); } decrRefCount(key); diff --git a/src/redis.c b/src/redis.c index 501d04a9..3ad35117 100644 --- a/src/redis.c +++ b/src/redis.c @@ -886,7 +886,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { if (!server.sentinel_mode) { run_with_period(5000) { redisLog(REDIS_VERBOSE, - "%d clients connected (%d slaves), %zu bytes in use", + "%lu clients connected (%lu slaves), %zu bytes in use", listLength(server.clients)-listLength(server.slaves), listLength(server.slaves), zmalloc_used_memory()); @@ -935,7 +935,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { if (server.dirty >= sp->changes && server.unixtime-server.lastsave > sp->seconds) { redisLog(REDIS_NOTICE,"%d changes in %d seconds. Saving...", - sp->changes, sp->seconds); + sp->changes, (int)sp->seconds); rdbSaveBackground(server.rdb_filename); break; } diff --git a/src/redis.h b/src/redis.h index d2a6a4fb..90ff59ab 100644 --- a/src/redis.h +++ b/src/redis.h @@ -999,7 +999,12 @@ void call(redisClient *c, int flags); void propagate(struct redisCommand *cmd, int dbid, robj **argv, int argc, int flags); void alsoPropagate(struct redisCommand *cmd, int dbid, robj **argv, int argc, int target); int prepareForShutdown(); +#ifdef __GNUC__ +void redisLog(int level, const char *fmt, ...) + __attribute__((format(printf, 2, 3))); +#else void redisLog(int level, const char *fmt, ...); +#endif void redisLogRaw(int level, const char *msg); void redisLogFromHandler(int level, const char *msg); void usage(); diff --git a/src/replication.c b/src/replication.c index 3015886a..6583f322 100644 --- a/src/replication.c +++ b/src/replication.c @@ -759,8 +759,8 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) { } server.repl_transfer_size = strtol(buf+1,NULL,10); redisLog(REDIS_NOTICE, - "MASTER <-> SLAVE sync: receiving %ld bytes from master", - server.repl_transfer_size); + "MASTER <-> SLAVE sync: receiving %lld bytes from master", + (long long) server.repl_transfer_size); return; } @@ -1433,7 +1433,8 @@ void replicationCron(void) { freeReplicationBacklog(); redisLog(REDIS_NOTICE, "Replication backlog freed after %d seconds " - "without connected slaves.", server.repl_backlog_time_limit); + "without connected slaves.", + (int) server.repl_backlog_time_limit); } } } -- GitLab