From 2bbb6cfeb56b1f4dde58f7c18ddfefee923649c8 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg <bensberg@justemail.net> Date: Sat, 25 Feb 2017 11:17:12 +0100 Subject: [PATCH] wrapping: add the correct char length when skipping consecutive blanks In this last loop of break_line(), the pointer 'line' is one step ahead of the index 'lastblank'. So the loop should first add the length of the preceding character to 'lastblank' before determining the length of the current character (and using this to advance 'line'). --- src/text.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/text.c b/src/text.c index 592e5a78..5b7c0cf3 100644 --- a/src/text.c +++ b/src/text.c @@ -1674,15 +1674,16 @@ ssize_t break_line(const char *line, ssize_t goal, bool snap_at_nl) return -1; } + /* Move the pointer back to the last blank, and then step beyond it. */ line += lastblank - index; - line += parse_mbchar(line, NULL, NULL); + char_len = parse_mbchar(line, NULL, NULL); + line += char_len; - /* Skip any consecutive blanks after the last found blank. */ + /* Skip any consecutive blanks after the last blank. */ while (*line != '\0' && is_blank_mbchar(line)) { + lastblank += char_len; char_len = parse_mbchar(line, NULL, NULL); - line += char_len; - lastblank += char_len; } return lastblank; -- GitLab