summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--Src/Zle/zle_utils.c9
2 files changed, 11 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index e89305f4c..9e757799b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2005-08-12 Peter Stephenson <pws@csr.com>
+ * 21603: Src/Zle/zle_utils.c: conversions from wide character
+ to multibyte didn't convert the cursor position properly if it
+ was at the end of the line.
+
* 21412: Travis Spencer: Completion/Unix/Command/_pkg-config:
new completion.
diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index f8c4d2013..2e358f489 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -140,16 +140,19 @@ zlelineasstring(ZLE_STRING_T instr, int inll, int incs, int *outllp,
s = zalloc(inll * MB_CUR_MAX + 1);
outcs = 0;
- for(i=0; i < inll; i++, incs--) {
+ for (i=0; i < inll; i++, incs--) {
if (incs == 0)
outcs = mb_len;
j = wctomb(s + mb_len, instr[i]);
if (j == -1) {
/* invalid char; what to do? */
+ s[mb_len++] = ZWC('?');
} else {
mb_len += j;
}
}
+ if (incs == 0)
+ outcs = mb_len;
s[mb_len] = '\0';
outll = mb_len;
@@ -279,7 +282,7 @@ stringaszleline(unsigned char *instr, int incs,
/* Reset shift state to input complete string */
memset(&ps, '\0', sizeof(ps));
- while (ll) {
+ while (ll > 0) {
size_t ret = mbrtowc(outptr, inptr, ll, &ps);
/*
@@ -311,6 +314,8 @@ stringaszleline(unsigned char *instr, int incs,
outptr++;
ll -= ret;
}
+ if (outcs && inptr <= (char *)instr + incs)
+ *outcs = outptr - outstr;
*outll = outptr - outstr;
} else {
*outll = 0;