diff --git a/src/t_set.c b/src/t_set.c index 1c066e7008..efc3609d0b 100644 --- a/src/t_set.c +++ b/src/t_set.c @@ -139,16 +139,17 @@ int setTypeAddAux(robj *set, char *str, size_t len, int64_t llval, int str_is_sd /* Avoid duping the string if it is an sds string. */ sds sdsval = str_is_sds ? (sds)str : sdsnewlen(str, len); hashset *hs = set->ptr; - void *position = hashsetFindPositionForInsert(hs, sdsval, NULL); - if (position) { + hashsetPosition position; + if (hashsetFindPositionForInsert(hs, sdsval, &position, NULL)) { /* Key doesn't already exist in the set. Add it but dup the key. */ if (sdsval == str) sdsval = sdsdup(sdsval); - hashsetInsertAtPosition(hs, sdsval, position); + hashsetInsertAtPosition(hs, sdsval, &position); + return 1; } else if (sdsval != str) { /* String is already a member. Free our temporary sds copy. */ sdsfree(sdsval); + return 0; } - return (position != NULL); } else if (set->encoding == OBJ_ENCODING_LISTPACK) { unsigned char *lp = set->ptr; unsigned char *p = lpFirst(lp);