Skip to content

Commit 69c6023

Browse files
committed
fix: limit parameter exceeds the number of search results
Signed-off-by: zhangshuai.kv <[email protected]>
1 parent c50f841 commit 69c6023

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/commands/ft_search.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ void SendReplyNoContent(ValkeyModuleCtx *ctx,
6262
const std::deque<indexes::Neighbor> &neighbors,
6363
const query::SearchParameters &parameters) {
6464
const size_t start_index = CalcStartIndex(neighbors, parameters);
65-
const size_t end_index = start_index + CalcEndIndex(neighbors, parameters);
65+
const size_t end_index = std::min(start_index + CalcEndIndex(neighbors, parameters),
66+
neighbors.size());
6667
ValkeyModule_ReplyWithArray(ctx, end_index - start_index + 1);
6768
ReplyAvailNeighbors(ctx, neighbors, parameters);
6869
for (auto i = start_index; i < end_index; ++i) {
@@ -84,7 +85,8 @@ void SerializeNeighbors(ValkeyModuleCtx *ctx,
8485
const query::SearchParameters &parameters) {
8586
CHECK_GT(static_cast<size_t>(parameters.k), parameters.limit.first_index);
8687
const size_t start_index = CalcStartIndex(neighbors, parameters);
87-
const size_t end_index = start_index + CalcEndIndex(neighbors, parameters);
88+
const size_t end_index = std::min(start_index + CalcEndIndex(neighbors, parameters),
89+
neighbors.size());
8890
ValkeyModule_ReplyWithArray(ctx, 2 * (end_index - start_index) + 1);
8991
ReplyAvailNeighbors(ctx, neighbors, parameters);
9092

0 commit comments

Comments
 (0)