fix(core): fix iterator in backspace handling#15596
fix(core): fix iterator in backspace handling#15596ermshiperete wants to merge 2 commits intomasterfrom
Conversation
User Test ResultsTest specification and instructions User tests are not required Test Artifacts
|
For reference, I found the code in production: keyman/core/src/ldml/ldml_processor.cpp Lines 230 to 246 in 6540886 Would it be better if tests closely mirrored production? (Could the tests use a list where this works?) |
|
@ermshiperete I am wondering how you found this? |
While reading through the code I stumbled upon However, in checking the facts (which I neglected to do initially), it turns out that the code in I'll rework the PR. |
022a11a to
84f4def
Compare
This change replaces the reverse iterator loop that holds a stale iterator across `pop_back()` calls with a pattern that directly accesses `context.back()` on each iteration. This avoids undefined behavior from iterator invalidation when mutating the list or vector. While so far the previous code didn't show problems, it might still access released memory depending on the implementation. The documentation for `pop_back()` says "References and iterators to the erased element are invalidated", so the previous implementation was clearly wrong. Test-bot: skip
84f4def to
32bb1c8
Compare
Production code uses a list of context items, so this change modifies the tests to also use a list instead of a vector to more closely match production code. Addresses code review comment. Test-bot: skip
Done. Using list now. |
|
Fixed loop in |
Instead of using an iterator to loop over the context items, incrementing a counter on each iteration, and then finally removing the calculated number of context items from the list, this change loops through the list and looks at the last context item, removing it if necessary. Follows: #15596 Test-bot: skip
This change replaces the reverse iterator loop that holds a stale iterator across
pop_back()calls with a pattern that directly accessescontext.back()on each iteration. This avoids undefined behavior from iterator invalidation when mutating the list or vector.While so far the previous code didn't show problems, it might still access released memory depending on the implementation. The documentation for
pop_back()says "References and iterators to the erased element are invalidated", so the previous implementation was clearly wrong.Test-bot: skip