Skip to content

Commit

Permalink
Fix a heap-use-after-free error found by asan
Browse files Browse the repository at this point in the history
ctx->composition().Forward() might invalidated the iterator when did a
push_back, we can't use `seg` anymore.
  • Loading branch information
timxx committed Apr 16, 2018
1 parent 1a6e021 commit 030c389
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/rime/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ void ConcreteEngine::OnSelect(Context* ctx) {
ctx->composition().Forward();
}
else {
bool updateCaret = (seg.end >= ctx->caret_pos());
ctx->composition().Forward();
if (seg.end >= ctx->caret_pos()) {
if (updateCaret) {
// finished converting current segment
// move caret to the end of input
ctx->set_caret_pos(ctx->input().length());
Expand Down

0 comments on commit 030c389

Please # to comment.