This is an automated email from the ASF dual-hosted git repository.

jihuayu pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 797649012 fix(zset): initialize *inter_cnt before early return in 
InterCard (#3421)
797649012 is described below

commit 797649012faa4ebf010e1558ba891df67d68cfc9
Author: Songqing Zhang <[email protected]>
AuthorDate: Wed Apr 8 18:29:12 2026 +0800

    fix(zset): initialize *inter_cnt before early return in InterCard (#3421)
    
    When any input key is empty (mscores.empty()), InterCard returned OK
        without ever assigning *inter_cnt, leaving callers with an
        uninitialized value. Redis ZINTERCARD should return 0 in this case.
    
    Fix by initializing *inter_cnt = 0 at the function entry.
    
    Although the count at the caller layer is initialized to 0, which seems
    to be fortuitously safe, other potential callers (such as internal
    calls, test code, and future refactoring) may not necessarily initialize
    it beforehand.
    
    Co-authored-by: 纪华裕 <[email protected]>
---
 src/types/redis_zset.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/types/redis_zset.cc b/src/types/redis_zset.cc
index 333782b10..26a2aee70 100644
--- a/src/types/redis_zset.cc
+++ b/src/types/redis_zset.cc
@@ -706,6 +706,8 @@ rocksdb::Status ZSet::Inter(engine::Context &ctx, const 
std::vector<KeyWeight> &
 
 rocksdb::Status ZSet::InterCard(engine::Context &ctx, const 
std::vector<std::string> &user_keys, uint64_t limit,
                                 uint64_t *inter_cnt) {
+  *inter_cnt = 0;
+
   std::vector<MemberScores> mscores_list;
   mscores_list.reserve(user_keys.size());
   RangeScoreSpec spec;

Reply via email to