Fix recently broken escape_code_length() result
`escape_code_length()` was converted from returning a `size_t` to returning a `maybe_t<size_t>` but that subtly broke all existing call sites by forcing all input to go through the slow path of assuming a zero-length escape sequence was found. This is because all callers predicated their next action on what amounts to `if (escape_code_length(...))` which would correctly skip the slow path when `escape_code_length` returned zero, but after the conversion to `maybe_t` contained not `maybe_t::none()` but rather `maybe_t::some(0)` due to coercion of the result from the `size_t` local `esc_seq_len` to the `maybe_t<size_t>` return value - which, when coerced to a boolean returns *true* for `maybe_t::some(0)` rather than false. The regression was introduced in 7ad855a844a271770ad659622a10f9fe273566b4 and did not ship in any released versions so no harm, no foul.
This commit is contained in:
parent
daa366eb5a
commit
426fa82f8f
@ -249,7 +249,7 @@ static bool is_visual_escape_seq(const wchar_t *code, size_t *resulting_length)
|
||||
/// the escape sequence based on querying terminfo and other heuristics.
|
||||
maybe_t<size_t> escape_code_length(const wchar_t *code) {
|
||||
assert(code != nullptr);
|
||||
if (*code != L'\x1B') return 0;
|
||||
if (*code != L'\x1B') return none();
|
||||
|
||||
size_t esc_seq_len = 0;
|
||||
bool found = is_color_escape_seq(code, &esc_seq_len);
|
||||
@ -259,7 +259,8 @@ maybe_t<size_t> escape_code_length(const wchar_t *code) {
|
||||
if (!found) found = is_three_byte_escape_seq(code, &esc_seq_len);
|
||||
if (!found) found = is_csi_style_escape_seq(code, &esc_seq_len);
|
||||
if (!found) found = is_two_byte_escape_seq(code, &esc_seq_len);
|
||||
return esc_seq_len;
|
||||
|
||||
return found ? maybe_t<size_t>{esc_seq_len} : none();
|
||||
}
|
||||
|
||||
size_t layout_cache_t::escape_code_length(const wchar_t *code) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user