diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2020-12-10 09:58:43 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2020-12-10 10:00:32 +0900 |
commit | 6a7f187ce60c2d359b7e276787a01c290d7828e0 (patch) | |
tree | 5a9a6964767edd56da66904d35f909262f41bebf | |
parent | ec3a89115c47a72b426a73120bf6d2c211b4c77a (diff) | |
download | readline-tizen_6.5_base.tar.gz readline-tizen_6.5_base.tar.bz2 readline-tizen_6.5_base.zip |
Patch-ID: readline52-014tizen_7.0_m2_releasetizen_6.5.m2_releasesubmit/tizen_base/20201216.221453submit/tizen_base/20201210.010706submit/tizen_7.0_base_hotfix/20221115.161701submit/tizen_7.0_base/20221028.201301submit/tizen_6.5_base/20211027.201101submit/tizen_6.5_base/20211027.183101submit/tizen_6.5_base/20211026.180901accepted/tizen/base/tool/20201219.095646accepted/tizen/7.0/base/tool/hotfix/20221115.084343accepted/tizen/7.0/base/tool/20221028.120324accepted/tizen/7.0/base/hotfix/20230714.003922accepted/tizen/7.0/base/20230714.003112accepted/tizen/6.5/base/tool/20211027.120617accepted/tizen/6.5/base/20230714.002703tizen_7.0_base_hotfixtizen_7.0_basetizen_6.5_baseaccepted/tizen_7.0_base_tool_hotfixaccepted/tizen_7.0_base_toolaccepted/tizen_7.0_base_hotfixaccepted/tizen_7.0_baseaccepted/tizen_6.5_base_toolaccepted/tizen_6.5_base
Bug-Reported-by: Len Lattanzi <llattanzi@apple.com>
Bug-Reference-ID: <52B1297F-6675-45CC-B63E-24745337D006@apple.com>
Bug-Reference-URL:
Bug-Description:
On systems where mbrtowc() returns -2 when passed a length argument with
value 0, when using a multibyte locale, Readline's emacs-mode forward-char
at the end of a line will leave the point beyond the end of the line.
Change-Id: I73b50c94b0a0012803fb07f0f35bdc9c2ebaa7dd
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
-rw-r--r-- | mbutil.c | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -77,7 +77,7 @@ _rl_find_next_mbchar_internal (string, seed, count, find_non_zero) char *string; int seed, count, find_non_zero; { - size_t tmp; + size_t tmp, len; mbstate_t ps; int point; wchar_t wc; @@ -96,9 +96,12 @@ _rl_find_next_mbchar_internal (string, seed, count, find_non_zero) if (seed < point) count--; - while (count > 0) + while (count > 0) { - tmp = mbrtowc (&wc, string+point, strlen(string + point), &ps); + len = strlen (string + point); + if (len == 0) + break; + tmp = mbrtowc (&wc, string+point, len, &ps); if (MB_INVALIDCH ((size_t)tmp)) { /* invalid bytes. asume a byte represents a character */ @@ -152,7 +155,7 @@ _rl_find_prev_mbchar_internal (string, seed, find_non_zero) memset(&ps, 0, sizeof(mbstate_t)); length = strlen(string); - + if (seed < 0) return 0; else if (length < seed) @@ -186,7 +189,7 @@ _rl_find_prev_mbchar_internal (string, seed, find_non_zero) prev = point; } else - prev = point; + prev = point; } point += tmp; @@ -196,9 +199,9 @@ _rl_find_prev_mbchar_internal (string, seed, find_non_zero) } /* return the number of bytes parsed from the multibyte sequence starting - at src, if a non-L'\0' wide character was recognized. It returns 0, - if a L'\0' wide character was recognized. It returns (size_t)(-1), - if an invalid multibyte sequence was encountered. It returns (size_t)(-2) + at src, if a non-L'\0' wide character was recognized. It returns 0, + if a L'\0' wide character was recognized. It returns (size_t)(-1), + if an invalid multibyte sequence was encountered. It returns (size_t)(-2) if it couldn't parse a complete multibyte character. */ int _rl_get_char_len (src, ps) @@ -242,7 +245,7 @@ _rl_compare_chars (buf1, pos1, ps1, buf2, pos2, ps2) { int i, w1, w2; - if ((w1 = _rl_get_char_len (&buf1[pos1], ps1)) <= 0 || + if ((w1 = _rl_get_char_len (&buf1[pos1], ps1)) <= 0 || (w2 = _rl_get_char_len (&buf2[pos2], ps2)) <= 0 || (w1 != w2) || (buf1[pos1] != buf2[pos2])) @@ -275,7 +278,7 @@ _rl_adjust_point(string, point, ps) return -1; if (length < point) return -1; - + while (pos < point) { tmp = mbrlen (string + pos, length - pos, ps); @@ -334,7 +337,7 @@ _rl_char_value (buf, ind) return ((wchar_t) buf[ind]); memset (&ps, 0, sizeof (mbstate_t)); tmp = mbrtowc (&wc, buf + ind, l - ind, &ps); - if (MB_INVALIDCH (tmp) || MB_NULLWCH (tmp)) + if (MB_INVALIDCH (tmp) || MB_NULLWCH (tmp)) return ((wchar_t) buf[ind]); return wc; } |