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

fix(script_translator): correction can cause segfault #863

Merged
merged 5 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/rime/algo/syllabifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Corrector;
using SyllableId = int32_t;

struct EdgeProperties : SpellingProperties {
EdgeProperties(SpellingProperties sup) : SpellingProperties(sup){};
EdgeProperties(SpellingProperties sup) : SpellingProperties(sup) {};
EdgeProperties() = default;
bool is_correction = false;
};
Expand Down
4 changes: 3 additions & 1 deletion src/rime/gear/script_translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ bool ScriptTranslation::Next() {
} while (enable_correction_ &&
syllabifier_->IsCandidateCorrection(*candidate_) &&
// limit the number of correction candidates
++correction_count_ > max_corrections_);
Copy link
Member

@lotem lotem Apr 18, 2024

Choose a reason for hiding this comment

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

This while-loop is used to drop any correction candidates after the top N (max_corrections_).

If I didn't take it wrong, correction_count_ > max_corrections_ means exactly "correction candidates after the top N" so the loop goes on until the next non-correction candidate is found.

I recently updated this part. I might have broken it. Please blame and review my last change.
One thing that appear weird is the is_correction never set true.

++correction_count_ < max_corrections_);
++candidate_index_;
return !CheckEmpty();
}
Expand Down Expand Up @@ -528,6 +528,8 @@ bool ScriptTranslation::PrepareCandidate() {
candidate_->set_quality(std::exp(entry->weight) +
translator_->initial_quality() +
(IsNormalSpelling() ? 0 : -1));
} else {
return false;
}
return true;
}
Expand Down