summaryrefslogtreecommitdiff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/Zle/zle_utils.c16
-rw-r--r--Src/builtin.c10
2 files changed, 23 insertions, 3 deletions
diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index 6583ef503..a146b67c0 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -294,6 +294,16 @@ stringaszleline(char *instr, int incs, int *outll, int *outsz, int *outcs)
* (certainly true for Unicode and unlikely to be false
* in any non-pathological multibyte representation). */
cnt = 1;
+ } else if (cnt > ll) {
+ /*
+ * Some multibyte implementations return the
+ * full length of a previous incomplete character
+ * instead of the remaining length.
+ * This is paranoia: it only applies if we start
+ * midway through a multibyte character, which
+ * presumably can't happen.
+ */
+ cnt = ll;
}
if (outcs) {
@@ -843,6 +853,12 @@ showmsg(char const *msg)
cnt = 1;
/* FALL THROUGH */
default:
+ /*
+ * Paranoia: only needed if we start in the middle
+ * of a multibyte string and only in some implementations.
+ */
+ if (cnt > ulen)
+ cnt = ulen;
n = wcs_nicechar(c, &width, NULL);
break;
}
diff --git a/Src/builtin.c b/Src/builtin.c
index 7bd4c6d83..8ded1c131 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -4927,7 +4927,7 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
break;
}
*bptr = (char) val;
-#ifdef MULTIBYTE_SUPPORT
+#ifdef MULTIBYTE_SUPPORT
if (isset(MULTIBYTE)) {
ret = mbrlen(bptr++, 1, &mbs);
if (ret == MB_INVALID)
@@ -4954,8 +4954,8 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
eof = 1;
break;
}
-
-#ifdef MULTIBYTE_SUPPORT
+
+#ifdef MULTIBYTE_SUPPORT
if (isset(MULTIBYTE)) {
while (val > 0) {
ret = mbrlen(bptr, val, &mbs);
@@ -4970,6 +4970,10 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
}
else if (ret == 0) /* handle null as normal char */
ret = 1;
+ else if (ret > val) {
+ /* Some mbrlen()s return the full char len */
+ ret = val;
+ }
nchars--;
val -= ret;
bptr += ret;