diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2005-08-12 10:24:23 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2005-08-12 10:24:23 +0000 |
commit | 7f09a15a83ab868ece1b222cbab71d1456a413e2 (patch) | |
tree | 1e5f2e2b83ec6fc349ee0e422c5bf1b2299e21ed /Src/Zle | |
parent | 3da1974d5ca9e2245a2c2a27944370b3ac6eb39a (diff) | |
download | zsh-7f09a15a83ab868ece1b222cbab71d1456a413e2.tar.gz zsh-7f09a15a83ab868ece1b222cbab71d1456a413e2.tar.xz zsh-7f09a15a83ab868ece1b222cbab71d1456a413e2.zip |
21603: wchar/multibyte conversion of cursor position when at end of line
Diffstat (limited to 'Src/Zle')
-rw-r--r-- | Src/Zle/zle_utils.c | 9 |
1 files changed, 7 insertions, 2 deletions
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; |