diff --git a/ChangeLog b/ChangeLog index dd0eae797fca7931b5eff4c93800b2d82d5a43db..69032f0c40de93d2ca6a9b47e0f4c8dca167b5f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,8 @@ * src/text.c (break_line): Initialize a variable to avoid a compiler warning, rename it to be more apt, add a comment, tweak some others, and remove an unneeded 'if'. + * src/char.c (move_mbleft): Avoid a compiler warning (int → size_t), + rename the variable, and another, and straighten out the logic. 2014-04-13 Benno Schulenberg <bensberg@justemail.net> * proto.h, global.c, rcfile.c: Remove the unused parameter 'menu' diff --git a/src/chars.c b/src/chars.c index 58bfee95f97f68fbe8f97f767b2126bc0d31e3a7..7e502bbf2eaaa55d7e64b3b69beca854a1e3797f 100644 --- a/src/chars.c +++ b/src/chars.c @@ -472,22 +472,18 @@ int parse_mbchar(const char *buf, char *chr, size_t *col) * before the one at pos. */ size_t move_mbleft(const char *buf, size_t pos) { - size_t pos_prev = pos; + size_t before = 0, char_len = 0; assert(buf != NULL && pos <= strlen(buf)); /* There is no library function to move backward one multibyte * character. Here is the naive, O(pos) way to do it. */ - while (TRUE) { - int buf_mb_len = parse_mbchar(buf + pos - pos_prev, NULL, NULL); - - if (pos_prev <= buf_mb_len) - break; - - pos_prev -= buf_mb_len; + while (before < pos) { + char_len = parse_mbchar(buf + before, NULL, NULL); + before += char_len; } - return pos - pos_prev; + return before - char_len; } /* Return the index in buf of the beginning of the multibyte character