llvm-project
0d8b3362 - [lldb] Fix partial Unicode handling in TrimAndPad (#183299)

Commit
2 days ago
[lldb] Fix partial Unicode handling in TrimAndPad (#183299) This fixes an issue I found while writing a variant of TrimAndPad for word wrapping purposes. TrimAndPad relies on llvm::sys::locale::ColumnWidth returning an error value, when there is a partial uft8 character. This error code is ErrorInvalidUTF8, which is -2. The idea was that when you cast that into a size_t, it was always going to be larger than our target visible width. The check for this was: result_visibile_length + column_width <= visible_length Where result_visible_length and column_width are size_ts. And the idea is correct, as long as result_visible_width is not large enough to cause the result to wrap to be lower than visible_length. In other words: when we have accumulated some part of the string already, if we have to trim the next part, sometimes we would return an incomplete Unicode character. When we should instead carry on trimming. To fix this, I've made TrimAndPad check explicitly for the error code. Only if it's not found, will it cast to do the second check.
Author
Parents
Loading