From aefdc57f1eb20115ad0a8eb05d9637b08988524f Mon Sep 17 00:00:00 2001 From: "zhaozhao.zz" Date: Thu, 6 Jul 2023 13:17:25 +0800 Subject: [PATCH] add an assertion to make sure numkeys is 0 in getKeysUsingKeySpecs (#12389) This is an addition to #12380, to prevent potential bugs when collecting keys from multiple commands in the future. Note that this function also resets numkeys in some cases. --- src/db.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db.c b/src/db.c index 48462ddb0..7b34fcb47 100644 --- a/src/db.c +++ b/src/db.c @@ -1873,7 +1873,7 @@ int64_t getAllKeySpecsFlags(struct redisCommand *cmd, int inv) { int getKeysUsingKeySpecs(struct redisCommand *cmd, robj **argv, int argc, int search_flags, getKeysResult *result) { int j, i, last, first, step; keyReference *keys; - result->numkeys = 0; + serverAssert(result->numkeys == 0); /* caller should initialize or reset it */ for (j = 0; j < cmd->key_specs_num; j++) { keySpec *spec = cmd->key_specs + j;