Set: setType*() API more defensive initializing both values.

This change fixes several warnings compiling at -O3 level with GCC
4.8.2, and at the same time, in case of misuse of the API, we have the
pointer initialize to NULL or the integer initialized to the value
-123456789 which is easy to spot by naked eye.
This commit is contained in:
antirez 2015-03-30 12:24:57 +02:00
parent 34460dd6ee
commit 7f330b16f9

View File

@ -154,9 +154,13 @@ int setTypeNext(setTypeIterator *si, robj **objele, int64_t *llele) {
dictEntry *de = dictNext(si->di); dictEntry *de = dictNext(si->di);
if (de == NULL) return -1; if (de == NULL) return -1;
*objele = dictGetKey(de); *objele = dictGetKey(de);
*llele = -123456789; /* Not needed. Defensive. */
} else if (si->encoding == REDIS_ENCODING_INTSET) { } else if (si->encoding == REDIS_ENCODING_INTSET) {
if (!intsetGet(si->subject->ptr,si->ii++,llele)) if (!intsetGet(si->subject->ptr,si->ii++,llele))
return -1; return -1;
*objele = NULL; /* Not needed. Defensive. */
} else {
redisPanic("Wrong set encoding in setTypeNext");
} }
return si->encoding; return si->encoding;
} }
@ -204,8 +208,10 @@ int setTypeRandomElement(robj *setobj, robj **objele, int64_t *llele) {
if (setobj->encoding == REDIS_ENCODING_HT) { if (setobj->encoding == REDIS_ENCODING_HT) {
dictEntry *de = dictGetRandomKey(setobj->ptr); dictEntry *de = dictGetRandomKey(setobj->ptr);
*objele = dictGetKey(de); *objele = dictGetKey(de);
*llele = -123456789; /* Not needed. Defensive. */
} else if (setobj->encoding == REDIS_ENCODING_INTSET) { } else if (setobj->encoding == REDIS_ENCODING_INTSET) {
*llele = intsetRandom(setobj->ptr); *llele = intsetRandom(setobj->ptr);
*objele = NULL; /* Not needed. Defensive. */
} else { } else {
redisPanic("Unknown set encoding"); redisPanic("Unknown set encoding");
} }