Clean up lookahead-related code#25
Conversation
Co-authored-by: Ozan Tezcan <ozantezcan@gmail.com>
Code Review by Qodo
1. Off-by-one loop in slot scan
|
| for (int j = 0; j <= keys_result->numkeys; j++) { | ||
| robj *this_key = argv[keys_result->keys[j].pos]; | ||
| int this_slot = (int)keyHashSlot((char*)this_key->ptr, sdslen(this_key->ptr)); | ||
| slot_buffer[j] = this_slot; |
There was a problem hiding this comment.
1. Off-by-one loop in slot scan 📘 Rule violation ⛯ Reliability
• extractSlotFromKeysResult() iterates with j <= keys_result->numkeys, which reads keys_result->keys[numkeys] and writes slot_buffer[numkeys] out of bounds. • This is a missing boundary/edge-case handling issue that can lead to crashes or memory corruption under normal inputs.
Agent prompt
## Issue description
`extractSlotFromKeysResult()` has an off-by-one loop (`<=`) that can access past the end of `keys_result->keys` and the `slot_buffer`.
## Issue Context
This is a boundary-value bug (j==numkeys) that can cause memory corruption.
## Fix Focus Areas
- src/cluster.c[1112-1115]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| if (num_keys > 0) { | ||
| *slot = extractSlotFromKeysResult(argv, result); | ||
|
|
||
| } |
There was a problem hiding this comment.
2. *slot not set for zero keys 📘 Rule violation ⛯ Reliability
• extractKeysAndSlot() documents that the slot is returned via *slot, but it only assigns *slot when num_keys > 0. • When num_keys == 0 (or negative), *slot may retain a stale value from the caller, causing incorrect behavior in downstream logic that relies on *slot being valid/initialized.
Agent prompt
## Issue description
`extractKeysAndSlot()` may leave `*slot` uninitialized/stale when `num_keys` is 0 or negative.
## Issue Context
The function contract says the slot is returned via `*slot`, so callers may rely on it being set even for the no-keys path.
## Fix Focus Areas
- src/db.c[3176-3204]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Benchmark PR from agentic-review-benchmarks#3