From c49378fe3e6f8900e753ff60a1b1f59e2e2c8755 Mon Sep 17 00:00:00 2001 From: Kashif Rasul Date: Fri, 4 Apr 2014 10:25:40 +0200 Subject: [PATCH] Fix issues raised by clang analyzer Modified by @antirez since the original fix to genInfoString() looked weak. Probably the clang analyzer complained about `section` being possibly NULL, and strcasecmp() called with a NULL pointer. In the practice this can never happen, still for the sake of correctness the right fix is not to modify only the first call, but to set `section` to the value of "default" if it happens to be NULL. Closes #1660 --- src/redis-cli.c | 1 + src/redis.c | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 89afbbcb..eafeb190 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -644,6 +644,7 @@ static int cliSendCommand(int argc, char **argv, int repeat) { printf("Entering slave output mode... (press Ctrl-C to quit)\n"); slaveMode(); config.slave_mode = 0; + free(argvlen); return REDIS_ERR; /* Error = slaveMode lost connection to master */ } diff --git a/src/redis.c b/src/redis.c index c5c3f79b..dff480c0 100644 --- a/src/redis.c +++ b/src/redis.c @@ -2562,10 +2562,9 @@ sds genRedisInfoString(char *section) { int allsections = 0, defsections = 0; int sections = 0; - if (section) { - allsections = strcasecmp(section,"all") == 0; - defsections = strcasecmp(section,"default") == 0; - } + if (section == NULL) section = "default"; + allsections = strcasecmp(section,"all") == 0; + defsections = strcasecmp(section,"default") == 0; getrusage(RUSAGE_SELF, &self_ru); getrusage(RUSAGE_CHILDREN, &c_ru);