Skip to content

Clean up lookahead-related code#3

Open
tomerqodo wants to merge 7 commits intocursor_full_base_clean_up_lookahead-related_code_pr3from
cursor_full_head_clean_up_lookahead-related_code_pr3
Open

Clean up lookahead-related code#3
tomerqodo wants to merge 7 commits intocursor_full_base_clean_up_lookahead-related_code_pr3from
cursor_full_head_clean_up_lookahead-related_code_pr3

Conversation

@tomerqodo
Copy link
Copy Markdown

@tomerqodo tomerqodo commented Jan 26, 2026

Benchmark PR from agentic-review-benchmarks#3


Note

Unifies slot handling to improve consistency across cluster operations.

  • Introduces CLUSTER_CROSSSLOT and uses INVALID_CLUSTER_SLOT in place of legacy GETSLOT_* values; removes old macros from server.h
  • Refactors extractSlotFromKeysResult and updates getSlotFromCommand to delegate to it for consistent slot derivation
  • Aligns cross-slot and no-keys logic in cluster_asm.c (propagation checks), cluster_slot_stats.c (stats gating), and command preprocessing in server.c
  • Adjusts callers to treat INVALID_CLUSTER_SLOT as no-keys/disabled-cluster and CLUSTER_CROSSSLOT as cross-slot errors; minor comment clarifications in networking.c

Written by Cursor Bugbot for commit cfae119. Configure here.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment thread src/cluster.c
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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off-by-one error causes out-of-bounds memory access

High Severity

The loop condition j <= keys_result->numkeys iterates one too many times. When j equals numkeys, both keys_result->keys[j] and slot_buffer[j] are accessed out of bounds. The slot_buffer is allocated with numkeys elements (indices 0 to numkeys-1), and keys_result->keys similarly has numkeys entries. The condition should be j < keys_result->numkeys to match all other similar loops in the codebase.

Fix in Cursor Fix in Web

Comment thread src/cluster.c
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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused slot_buffer allocation is dead code

Low Severity

The slot_buffer array is allocated and written to but never read. The function's logic only compares first_slot with this_slot to detect cross-slot keys—the values stored in slot_buffer serve no purpose. The buffer is allocated, populated on each iteration, and then freed without ever being used for any computation or return value.

Additional Locations (1)

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants