Skip to content

Commit

Permalink
Remove warnings and improve integer sign correctness.
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Aug 13, 2014
1 parent 7e3ccdd commit edca2b1
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 48 deletions.
2 changes: 2 additions & 0 deletions src/anet.c
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/aof.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.");
Expand Down
20 changes: 11 additions & 9 deletions src/bitops.c
Expand Up @@ -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
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/cluster.c
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/config.c
Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions src/db.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/dict.c
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/dict.h
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/hyperloglog.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/latency.c
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/networking.c
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/redis-benchmark.c
Expand Up @@ -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. */
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/redis-cli.c
Expand Up @@ -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;i<keys->elements;i++) {
Expand Down Expand Up @@ -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;i<keys->elements;i++) {
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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++)
Expand Down
16 changes: 8 additions & 8 deletions src/redis.c
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/redis.h
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/scripting.c
Expand Up @@ -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) {
Expand Down

0 comments on commit edca2b1

Please sign in to comment.