Skip to content

Commit

Permalink
fix(table_translator): index out of bound access in string
Browse files Browse the repository at this point in the history
when trying to add blank to preedit then increase pos, might lead to
input[pos - 1] out of bound.

`pos` is tracking string variable `preedit`, they should be updated in
sync. checking delimiters at word ending should also refer to
`preedit` instead of the unchanged `input_`.
  • Loading branch information
TsinamLeung authored and lotem committed Jan 9, 2021
1 parent 1fad0b8 commit ff7acdc
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/rime/gear/table_translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ void SentenceTranslation::PrepareSentence() {
// split syllables
size_t pos = 0;
for (int len : sentence_->word_lengths()) {
if (pos > 0 && delimiters.find(input_[pos - 1]) == string::npos) {
if (pos > 0 && delimiters.find(preedit[pos - 1]) == string::npos) {
preedit.insert(pos, 1, ' ');
++pos;
}
Expand Down

0 comments on commit ff7acdc

Please sign in to comment.