From ff7acdc36b30582f8720e445cd01505fbcc51624 Mon Sep 17 00:00:00 2001 From: Chiram <44694735+ZenamLeong@users.noreply.github.com> Date: Fri, 8 Jan 2021 21:27:40 +0800 Subject: [PATCH] fix(table_translator): index out of bound access in string 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_`. --- src/rime/gear/table_translator.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rime/gear/table_translator.cc b/src/rime/gear/table_translator.cc index 731d9037de..162ac02449 100644 --- a/src/rime/gear/table_translator.cc +++ b/src/rime/gear/table_translator.cc @@ -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; }