diff --git a/src/anet.c b/src/anet.c index c053ccf8876b..76915326fa2d 100644 --- a/src/anet.c +++ b/src/anet.c @@ -117,6 +117,8 @@ int anetKeepAlive(char *err, int fd, int interval) anetSetError(err, "setsockopt TCP_KEEPCNT: %s\n", strerror(errno)); return ANET_ERR; } +#else + ((void) interval); /* Avoid unused var warning for non Linux systems. */ #endif return ANET_OK; diff --git a/src/aof.c b/src/aof.c index a2ef2df93349..5d46a21c4c18 100644 --- a/src/aof.c +++ b/src/aof.c @@ -95,6 +95,10 @@ void aofChildWriteDiffData(aeEventLoop *el, int fd, void *privdata, int mask) { listNode *ln; aofrwblock *block; ssize_t nwritten; + REDIS_NOTUSED(el); + REDIS_NOTUSED(fd); + REDIS_NOTUSED(privdata); + REDIS_NOTUSED(mask); while(1) { ln = listFirst(server.aof_rewrite_buf_blocks); @@ -177,7 +181,7 @@ ssize_t aofRewriteBufferWrite(int fd) { if (block->used) { nwritten = write(fd,block->buf,block->used); - if (nwritten != block->used) { + if (nwritten != (ssize_t)block->used) { if (nwritten == 0) errno = EIO; return -1; } @@ -1128,6 +1132,9 @@ int rewriteAppendOnlyFile(char *filename) { * parent sends a '!' as well to acknowledge. */ void aofChildPipeReadable(aeEventLoop *el, int fd, void *privdata, int mask) { char byte; + REDIS_NOTUSED(el); + REDIS_NOTUSED(privdata); + REDIS_NOTUSED(mask); if (read(fd,&byte,1) == 1 && byte == '!') { redisLog(REDIS_NOTICE,"AOF rewrite child asks to stop sending diffs."); diff --git a/src/bitops.c b/src/bitops.c index 28f7724302a4..94c7f3537b37 100644 --- a/src/bitops.c +++ b/src/bitops.c @@ -107,12 +107,12 @@ size_t redisPopcount(void *s, long count) { * no zero bit is found, it returns count*8 assuming the string is zero * padded on the right. However if 'bit' is 1 it is possible that there is * not a single set bit in the bitmap. In this special case -1 is returned. */ -long redisBitpos(void *s, long count, int bit) { +long redisBitpos(void *s, unsigned long count, int bit) { unsigned long *l; unsigned char *c; unsigned long skipval, word = 0, one; long pos = 0; /* Position of bit, to return to the caller. */ - int j; + unsigned long j; /* Process whole words first, seeking for first word that is not * all ones or all zeros respectively if we are lookig for zeros @@ -276,11 +276,12 @@ void getbitCommand(redisClient *c) { void bitopCommand(redisClient *c) { char *opname = c->argv[1]->ptr; robj *o, *targetkey = c->argv[2]; - long op, j, numkeys; + unsigned long op, j, numkeys; robj **objects; /* Array of source objects. */ unsigned char **src; /* Array of source strings pointers. */ - long *len, maxlen = 0; /* Array of length of src strings, and max len. */ - long minlen = 0; /* Min len among the input keys. */ + unsigned long *len, maxlen = 0; /* Array of length of src strings, + and max len. */ + unsigned long minlen = 0; /* Min len among the input keys. */ unsigned char *res = NULL; /* Resulting string. */ /* Parse the operation name. */ @@ -320,9 +321,10 @@ void bitopCommand(redisClient *c) { } /* Return an error if one of the keys is not a string. */ if (checkType(c,o,REDIS_STRING)) { - for (j = j-1; j >= 0; j--) { - if (objects[j]) - decrRefCount(objects[j]); + unsigned long i; + for (i = 0; i < j; i++) { + if (objects[i]) + decrRefCount(objects[i]); } zfree(src); zfree(len); @@ -340,7 +342,7 @@ void bitopCommand(redisClient *c) { if (maxlen) { res = (unsigned char*) sdsnewlen(NULL,maxlen); unsigned char output, byte; - long i; + unsigned long i; /* Fast path: as far as we have data for all the input bitmaps we * can take a fast path that performs much better than the diff --git a/src/cluster.c b/src/cluster.c index 81f82f938329..005a6ba54794 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -323,7 +323,7 @@ int clusterSaveConfig(int do_fsync) { /* Pad the new payload if the existing file length is greater. */ if (fstat(fd,&sb) != -1) { - if (sb.st_size > content_size) { + if (sb.st_size > (off_t)content_size) { ci = sdsgrowzero(ci,sb.st_size); memset(ci+content_size,'\n',sb.st_size-content_size); } @@ -1907,7 +1907,7 @@ void clusterReadHandler(aeEventLoop *el, int fd, void *privdata, int mask) { ssize_t nread; clusterMsg *hdr; clusterLink *link = (clusterLink*) privdata; - int readlen, rcvbuflen; + unsigned int readlen, rcvbuflen; REDIS_NOTUSED(el); REDIS_NOTUSED(mask); @@ -3982,7 +3982,7 @@ void clusterCommand(redisClient *c) { "configEpoch set to %llu via CLUSTER SET-CONFIG-EPOCH", (unsigned long long) myself->configEpoch); - if (server.cluster->currentEpoch < epoch) + if (server.cluster->currentEpoch < (uint64_t)epoch) server.cluster->currentEpoch = epoch; /* No need to fsync the config here since in the unlucky event * of a failure to persist the config, the conflict resolution code diff --git a/src/config.c b/src/config.c index 04246fcb6c5c..2aff1351f6c0 100644 --- a/src/config.c +++ b/src/config.c @@ -629,7 +629,7 @@ void configSetCommand(redisClient *c) { server.maxclients = orig_value; return; } - if (aeGetSetSize(server.el) < + if ((unsigned int) aeGetSetSize(server.el) < server.maxclients + REDIS_EVENTLOOP_FDSET_INCR) { if (aeResizeSetSize(server.el, diff --git a/src/db.c b/src/db.c index e665008ebb75..8eb1b89a7722 100644 --- a/src/db.c +++ b/src/db.c @@ -421,9 +421,7 @@ int parseScanCursorOrReply(redisClient *c, robj *o, unsigned long *cursor) { * In the case of a Hash object the function returns both the field and value * of every element on the Hash. */ void scanGenericCommand(redisClient *c, robj *o, unsigned long cursor) { - int rv; int i, j; - char buf[REDIS_LONGSTR_SIZE]; list *keys = listCreate(); listNode *node, *nextnode; long count = 10; @@ -503,7 +501,7 @@ void scanGenericCommand(redisClient *c, robj *o, unsigned long cursor) { privdata[1] = o; do { cursor = dictScan(ht, cursor, scanCallback, privdata); - } while (cursor && listLength(keys) < count); + } while (cursor && listLength(keys) < (unsigned long)count); } else if (o->type == REDIS_SET) { int pos = 0; int64_t ll; @@ -577,9 +575,7 @@ void scanGenericCommand(redisClient *c, robj *o, unsigned long cursor) { /* Step 4: Reply to the client. */ addReplyMultiBulkLen(c, 2); - rv = snprintf(buf, sizeof(buf), "%lu", cursor); - redisAssert(rv < sizeof(buf)); - addReplyBulkCBuffer(c, buf, rv); + addReplyBulkLongLong(c,cursor); addReplyMultiBulkLen(c, listLength(keys)); while ((node = listFirst(keys)) != NULL) { diff --git a/src/dict.c b/src/dict.c index b27920a446e5..42e75fc22b3b 100644 --- a/src/dict.c +++ b/src/dict.c @@ -668,9 +668,9 @@ dictEntry *dictGetRandomKey(dict *d) * statistics. However the function is much faster than dictGetRandomKey() * at producing N elements, and the elements are guaranteed to be non * repeating. */ -int dictGetRandomKeys(dict *d, dictEntry **des, int count) { +unsigned int dictGetRandomKeys(dict *d, dictEntry **des, unsigned int count) { int j; /* internal hash table id, 0 or 1. */ - int stored = 0; + unsigned int stored = 0; if (dictSize(d) < count) count = dictSize(d); while(stored < count) { diff --git a/src/dict.h b/src/dict.h index 905330f5d7b9..042eb54f757e 100644 --- a/src/dict.h +++ b/src/dict.h @@ -162,7 +162,7 @@ dictIterator *dictGetSafeIterator(dict *d); dictEntry *dictNext(dictIterator *iter); void dictReleaseIterator(dictIterator *iter); dictEntry *dictGetRandomKey(dict *d); -int dictGetRandomKeys(dict *d, dictEntry **des, int count); +unsigned int dictGetRandomKeys(dict *d, dictEntry **des, unsigned int count); void dictPrintStats(dict *d); unsigned int dictGenHashFunction(const void *key, int len); unsigned int dictGenCaseHashFunction(const unsigned char *buf, int len); diff --git a/src/hyperloglog.c b/src/hyperloglog.c index 63052a7897af..005beb18f587 100644 --- a/src/hyperloglog.c +++ b/src/hyperloglog.c @@ -1349,7 +1349,7 @@ void pfmergeCommand(redisClient *c) { * Something that is not easy to test from within the outside. */ #define HLL_TEST_CYCLES 1000 void pfselftestCommand(redisClient *c) { - int j, i; + unsigned int j, i; sds bitcounters = sdsnewlen(NULL,HLL_DENSE_SIZE); struct hllhdr *hdr = (struct hllhdr*) bitcounters, *hdr2; robj *o = NULL; @@ -1431,7 +1431,7 @@ void pfselftestCommand(redisClient *c) { if (j == 10) maxerr = 1; if (abserr < 0) abserr = -abserr; - if (abserr > maxerr) { + if (abserr > (int64_t)maxerr) { addReplyErrorFormat(c, "TESTFAILED Too big error. card:%llu abserr:%llu", (unsigned long long) checkpoint, diff --git a/src/latency.c b/src/latency.c index fdc88210e3f6..b7845ca296aa 100644 --- a/src/latency.c +++ b/src/latency.c @@ -37,6 +37,7 @@ /* Dictionary type for latency events. */ int dictStringKeyCompare(void *privdata, const void *key1, const void *key2) { + REDIS_NOTUSED(privdata); return strcmp(key1,key2) == 0; } diff --git a/src/networking.c b/src/networking.c index 9c100db1960e..fb49b7964ee4 100644 --- a/src/networking.c +++ b/src/networking.c @@ -1051,7 +1051,7 @@ int processMultibulkBuffer(redisClient *c) { qblen = sdslen(c->querybuf); /* Hint the sds library about the amount of bytes this string is * going to contain. */ - if (qblen < ll+2) + if (qblen < (size_t)ll+2) c->querybuf = sdsMakeRoomFor(c->querybuf,ll+2-qblen); } c->bulklen = ll; diff --git a/src/redis-benchmark.c b/src/redis-benchmark.c index 5ab2625d291b..e6d6f5738666 100644 --- a/src/redis-benchmark.c +++ b/src/redis-benchmark.c @@ -213,7 +213,7 @@ static void readHandler(aeEventLoop *el, int fd, void *privdata, int mask) { freeReplyObject(reply); if (c->selectlen) { - int j; + size_t j; /* This is the OK from SELECT. Just discard the SELECT * from the buffer. */ @@ -359,7 +359,7 @@ static client createClient(char *cmd, size_t len, client from) { c->randfree = 0; c->randptr = zmalloc(sizeof(char*)*c->randlen); /* copy the offsets. */ - for (j = 0; j < c->randlen; j++) { + for (j = 0; j < (int)c->randlen; j++) { c->randptr[j] = c->obuf + (from->randptr[j]-from->obuf); /* Adjust for the different select prefix length. */ c->randptr[j] += c->selectlen - from->selectlen; diff --git a/src/redis-cli.c b/src/redis-cli.c index 43a3556077f9..2e13d30603fa 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -1416,7 +1416,7 @@ static int toIntType(char *key, char *type) { static void getKeyTypes(redisReply *keys, int *types) { redisReply *reply; - int i; + unsigned int i; /* Pipeline TYPE commands */ for(i=0;ielements;i++) { @@ -1445,7 +1445,7 @@ static void getKeySizes(redisReply *keys, int *types, { redisReply *reply; char *sizecmds[] = {"STRLEN","LLEN","SCARD","HLEN","ZCARD"}; - int i; + unsigned int i; /* Pipeline size commands */ for(i=0;ielements;i++) { @@ -1492,7 +1492,8 @@ static void findBigKeys(void) { char *typename[] = {"string","list","set","hash","zset"}; char *typeunit[] = {"bytes","items","members","fields","members"}; redisReply *reply, *keys; - int type, *types=NULL, arrsize=0, i; + unsigned int arrsize=0, i; + int type, *types=NULL; double pct; /* Total keys pre scanning */ @@ -1779,7 +1780,7 @@ static void scanMode(void) { printf("ERROR: %s\n", reply->str); exit(1); } else { - int j; + unsigned int j; cur = strtoull(reply->element[0]->str,NULL,10); for (j = 0; j < reply->element[1]->elements; j++) diff --git a/src/redis.c b/src/redis.c index ff4cbb176f5f..e2df48825e85 100644 --- a/src/redis.c +++ b/src/redis.c @@ -760,8 +760,8 @@ void activeExpireCycle(int type) { static int timelimit_exit = 0; /* Time limit hit in previous call? */ static long long last_fast_cycle = 0; /* When last fast cycle ran. */ - unsigned int j, iteration = 0; - unsigned int dbs_per_call = REDIS_DBCRON_DBS_PER_CALL; + int j, iteration = 0; + int dbs_per_call = REDIS_DBCRON_DBS_PER_CALL; long long start = ustime(), timelimit; if (type == ACTIVE_EXPIRE_CYCLE_FAST) { @@ -1000,8 +1000,8 @@ void databasesCron(void) { * cron loop iteration. */ static unsigned int resize_db = 0; static unsigned int rehash_db = 0; - unsigned int dbs_per_call = REDIS_DBCRON_DBS_PER_CALL; - unsigned int j; + int dbs_per_call = REDIS_DBCRON_DBS_PER_CALL; + int j; /* Don't test more DBs than we have. */ if (dbs_per_call > server.dbnum) dbs_per_call = server.dbnum; @@ -1557,7 +1557,7 @@ void adjustOpenFilesLimit(void) { * to the higher value supported less than maxfiles. */ f = maxfiles; while(f > oldlimit) { - int decr_step = 16; + rlim_t decr_step = 16; limit.rlim_cur = f; limit.rlim_max = f; @@ -2359,9 +2359,9 @@ int time_independent_strcmp(char *a, char *b) { * a or b are fixed (our password) length, and the difference is only * relative to the length of the user provided string, so no information * leak is possible in the following two lines of code. */ - int alen = strlen(a); - int blen = strlen(b); - int j; + unsigned int alen = strlen(a); + unsigned int blen = strlen(b); + unsigned int j; int diff = 0; /* We can't compare strings longer than our static buffers. diff --git a/src/redis.h b/src/redis.h index 75c353fc06b0..c352cd79a778 100644 --- a/src/redis.h +++ b/src/redis.h @@ -814,12 +814,12 @@ struct redisServer { /* Replication script cache. */ dict *repl_scriptcache_dict; /* SHA1 all slaves are aware of. */ list *repl_scriptcache_fifo; /* First in, first out LRU eviction. */ - int repl_scriptcache_size; /* Max number of elements. */ + unsigned int repl_scriptcache_size; /* Max number of elements. */ /* Synchronous replication. */ list *clients_waiting_acks; /* Clients waiting in WAIT command. */ int get_ack_from_slaves; /* If true we send REPLCONF GETACK. */ /* Limits */ - int maxclients; /* Max number of simultaneous clients */ + unsigned int maxclients; /* Max number of simultaneous clients */ unsigned long long maxmemory; /* Max number of memory bytes to use */ int maxmemory_policy; /* Policy for key eviction */ int maxmemory_samples; /* Pricision of random sampling */ diff --git a/src/scripting.c b/src/scripting.c index 0a511e9817ad..a0c88742f5cd 100644 --- a/src/scripting.c +++ b/src/scripting.c @@ -212,7 +212,7 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) { static robj **argv = NULL; static int argv_size = 0; static robj *cached_objects[LUA_CMD_OBJCACHE_SIZE]; - static int cached_objects_len[LUA_CMD_OBJCACHE_SIZE]; + static size_t cached_objects_len[LUA_CMD_OBJCACHE_SIZE]; /* Require at least one argument */ if (argc == 0) { diff --git a/src/sentinel.c b/src/sentinel.c index 48e1de8ddd21..61ca3000a3fd 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -159,7 +159,7 @@ typedef struct sentinelRedisInstance { /* Master specific. */ dict *sentinels; /* Other sentinels monitoring the same master. */ dict *slaves; /* Slaves for this master instance. */ - int quorum; /* Number of sentinels that need to agree on failure. */ + unsigned int quorum;/* Number of sentinels that need to agree on failure. */ int parallel_syncs; /* How many slaves to reconfigure at same time. */ char *auth_pass; /* Password to use for AUTH against master & slaves. */ @@ -345,6 +345,7 @@ int dictSdsKeyCompare(void *privdata, const void *key1, const void *key2); void releaseSentinelRedisInstance(sentinelRedisInstance *ri); void dictInstancesValDestructor (void *privdata, void *obj) { + REDIS_NOTUSED(privdata); releaseSentinelRedisInstance(obj); } @@ -403,7 +404,7 @@ void initSentinelConfig(void) { /* Perform the Sentinel mode initialization. */ void initSentinel(void) { - int j; + unsigned int j; /* Remove usual Redis commands from the command table, then just add * the SENTINEL command. */ @@ -1634,6 +1635,7 @@ void sentinelLinkEstablishedCallback(const redisAsyncContext *c, int status) { } void sentinelDisconnectCallback(const redisAsyncContext *c, int status) { + REDIS_NOTUSED(status); sentinelDisconnectInstanceFromContext(c); } @@ -1998,6 +2000,7 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) { void sentinelInfoReplyCallback(redisAsyncContext *c, void *reply, void *privdata) { sentinelRedisInstance *ri = c->data; redisReply *r; + REDIS_NOTUSED(privdata); if (ri) ri->pending_commands--; if (!reply || !ri) return; @@ -2012,6 +2015,8 @@ void sentinelInfoReplyCallback(redisAsyncContext *c, void *reply, void *privdata * value of the command but its effects directly. */ void sentinelDiscardReplyCallback(redisAsyncContext *c, void *reply, void *privdata) { sentinelRedisInstance *ri = c->data; + REDIS_NOTUSED(reply); + REDIS_NOTUSED(privdata); if (ri) ri->pending_commands--; } @@ -2019,6 +2024,7 @@ void sentinelDiscardReplyCallback(redisAsyncContext *c, void *reply, void *privd void sentinelPingReplyCallback(redisAsyncContext *c, void *reply, void *privdata) { sentinelRedisInstance *ri = c->data; redisReply *r; + REDIS_NOTUSED(privdata); if (ri) ri->pending_commands--; if (!reply || !ri) return; @@ -2057,6 +2063,7 @@ void sentinelPingReplyCallback(redisAsyncContext *c, void *reply, void *privdata void sentinelPublishReplyCallback(redisAsyncContext *c, void *reply, void *privdata) { sentinelRedisInstance *ri = c->data; redisReply *r; + REDIS_NOTUSED(privdata); if (ri) ri->pending_commands--; if (!reply || !ri) return; @@ -2166,6 +2173,7 @@ void sentinelProcessHelloMessage(char *hello, int hello_len) { void sentinelReceiveHelloMessages(redisAsyncContext *c, void *reply, void *privdata) { sentinelRedisInstance *ri = c->data; redisReply *r; + REDIS_NOTUSED(privdata); if (!reply || !ri) return; r = reply; @@ -2559,7 +2567,7 @@ sentinelRedisInstance *sentinelGetMasterByNameOrReplyError(redisClient *c, { sentinelRedisInstance *ri; - ri = dictFetchValue(sentinel.masters,c->argv[2]->ptr); + ri = dictFetchValue(sentinel.masters,name->ptr); if (!ri) { addReplyError(c,"No such master with that name"); return NULL; @@ -2997,7 +3005,7 @@ void sentinelCheckSubjectivelyDown(sentinelRedisInstance *ri) { void sentinelCheckObjectivelyDown(sentinelRedisInstance *master) { dictIterator *di; dictEntry *de; - int quorum = 0, odown = 0; + unsigned int quorum = 0, odown = 0; if (master->flags & SRI_S_DOWN) { /* Is down for enough sentinels? */ @@ -3034,6 +3042,7 @@ void sentinelCheckObjectivelyDown(sentinelRedisInstance *master) { void sentinelReceiveIsMasterDownReply(redisAsyncContext *c, void *reply, void *privdata) { sentinelRedisInstance *ri = c->data; redisReply *r; + REDIS_NOTUSED(privdata); if (ri) ri->pending_commands--; if (!reply || !ri) return; @@ -3057,7 +3066,7 @@ void sentinelReceiveIsMasterDownReply(redisAsyncContext *c, void *reply, void *p /* If the runid in the reply is not "*" the Sentinel actually * replied with a vote. */ sdsfree(ri->leader); - if (ri->leader_epoch != r->element[2]->integer) + if ((long long)ri->leader_epoch != r->element[2]->integer) redisLog(REDIS_WARNING, "%s voted for %s %llu", ri->name, r->element[1]->str,