summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-03-30 12:24:57 +0200
committerantirez <antirez@gmail.com>2015-03-30 12:24:57 +0200
commit7f330b16f93d9feed0113e928a1b96f182b73e45 (patch)
treeb10589e1948aa240966d2f1335a00ffc285e5a2e
parent34460dd6ee0c9ae6561de54f1005f493bfcc543c (diff)
downloadredis-7f330b16f93d9feed0113e928a1b96f182b73e45.tar.gz
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.
-rw-r--r--src/t_set.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/t_set.c b/src/t_set.c
index c8141c3f6..44580098c 100644
--- a/src/t_set.c
+++ b/src/t_set.c
@@ -154,9 +154,13 @@ int setTypeNext(setTypeIterator *si, robj **objele, int64_t *llele) {
dictEntry *de = dictNext(si->di);
if (de == NULL) return -1;
*objele = dictGetKey(de);
+ *llele = -123456789; /* Not needed. Defensive. */
} else if (si->encoding == REDIS_ENCODING_INTSET) {
if (!intsetGet(si->subject->ptr,si->ii++,llele))
return -1;
+ *objele = NULL; /* Not needed. Defensive. */
+ } else {
+ redisPanic("Wrong set encoding in setTypeNext");
}
return si->encoding;
}
@@ -204,8 +208,10 @@ int setTypeRandomElement(robj *setobj, robj **objele, int64_t *llele) {
if (setobj->encoding == REDIS_ENCODING_HT) {
dictEntry *de = dictGetRandomKey(setobj->ptr);
*objele = dictGetKey(de);
+ *llele = -123456789; /* Not needed. Defensive. */
} else if (setobj->encoding == REDIS_ENCODING_INTSET) {
*llele = intsetRandom(setobj->ptr);
+ *objele = NULL; /* Not needed. Defensive. */
} else {
redisPanic("Unknown set encoding");
}