summaryrefslogtreecommitdiff
path: root/mbutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'mbutil.c')
-rw-r--r--mbutil.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/mbutil.c b/mbutil.c
index fac1460..6554341 100644
--- a/mbutil.c
+++ b/mbutil.c
@@ -92,6 +92,11 @@ _rl_find_next_mbchar_internal (char *string, int seed, int count, int find_non_z
return seed;
point = seed + _rl_adjust_point (string, seed, &ps);
+ /* if _rl_adjust_point returns -1, the character or string is invalid.
+ treat as a byte. */
+ if (point == seed - 1) /* invalid */
+ return seed + 1;
+
/* if this is true, means that seed was not pointing to a byte indicating
the beginning of a multibyte character. Correct the point and consume
one char. */
@@ -218,9 +223,13 @@ _rl_find_prev_mbchar_internal (char *string, int seed, int find_non_zero)
int
_rl_get_char_len (char *src, mbstate_t *ps)
{
- size_t tmp;
+ size_t tmp, l;
+ int mb_cur_max;
- tmp = mbrlen((const char *)src, (size_t)strlen (src), ps);
+ /* Look at no more than MB_CUR_MAX characters */
+ l = (size_t)strlen (src);
+ mb_cur_max = MB_CUR_MAX;
+ tmp = mbrlen((const char *)src, (l < mb_cur_max) ? l : mb_cur_max, ps);
if (tmp == (size_t)(-2))
{
/* shorted to compose multibyte char */
@@ -265,7 +274,7 @@ _rl_compare_chars (char *buf1, int pos1, mbstate_t *ps1, char *buf2, int pos2, m
/* adjust pointed byte and find mbstate of the point of string.
adjusted point will be point <= adjusted_point, and returns
differences of the byte(adjusted_point - point).
- if point is invalied (point < 0 || more than string length),
+ if point is invalid (point < 0 || more than string length),
it returns -1 */
int
_rl_adjust_point (char *string, int point, mbstate_t *ps)
@@ -336,6 +345,8 @@ _rl_char_value (char *buf, int ind)
l = strlen (buf);
if (ind >= l - 1)
return ((wchar_t) buf[ind]);
+ if (l < ind) /* Sanity check */
+ l = strlen (buf+ind);
memset (&ps, 0, sizeof (mbstate_t));
tmp = mbrtowc (&wc, buf + ind, l - ind, &ps);
if (MB_INVALIDCH (tmp) || MB_NULLWCH (tmp))