Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter check for index < 0 for Context::Highlight #867

Merged
merged 4 commits into from
Apr 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/rime/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
// 2011-05-08 GONG Chen <chen.sst@gmail.com>
//
#include <algorithm>
#include <utility>
#include <rime/candidate.h>
#include <rime/context.h>
Expand Down Expand Up @@ -127,12 +128,9 @@ bool Context::Highlight(size_t index) {
if (composition_.empty() || !composition_.back().menu)
return false;
Segment& seg(composition_.back());
size_t new_index = index;
size_t candidate_count = seg.menu->Prepare(index + 1);
if (index >= candidate_count) {
DLOG(INFO) << "selection index exceeds candidate pool, fallback to last";
new_index = candidate_count - 1;
}
size_t new_index =
candidate_count > 0 ? (std::min)(candidate_count - 1, index) : 0;
size_t previous_index = seg.selected_index;
if (previous_index == new_index) {
DLOG(INFO) << "selection has not changed, currently at " << new_index;
Expand Down