From ff8454a6f58738daadc1991bed2c2270f8e7063f Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Mon, 14 Apr 2014 20:42:10 +0000 Subject: [PATCH] Avoiding a compiler warning, and straightening out the logic. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4772 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 2 ++ src/chars.c | 14 +++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index dd0eae79..69032f0c 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 * proto.h, global.c, rcfile.c: Remove the unused parameter 'menu' diff --git a/src/chars.c b/src/chars.c index 58bfee95..7e502bbf 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 -- 2.39.5