commit 2d13beded20b1db3647de8a233c1d5b2ae2b4053
parent a9ae8a05932a697db41b90346be70cdab1e6031d
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Fri, 10 Oct 2014 22:45:57 +0000
fix delwordcursor and do some extra checks
Diffstat:
M | sob.c | | | 18 | +++++++++--------- |
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/sob.c b/sob.c
@@ -100,10 +100,10 @@ static size_t
colw(const char *s, size_t max)
{
size_t len = 0, i;
- wchar_t w = 0;
+ wchar_t w;
int r;
- for(i = 0; *s; s++, i++) {
+ for(i = 0; *s && i < max; s++, i++) {
if((*s & 0xc0) != 0x80) {
if((r = mbtowc(&w, s, i + 4 > max ? max - i : 4)) == -1)
break;
@@ -412,7 +412,7 @@ line_deltoend(void)
static void
line_delwordcursor(void)
{
- size_t len, siz, bs, be, us, ue;
+ size_t bs, be, us, ue, siz, len;
line_getwordpos(line.bytepos, line.utfpos, &bs, &be, &us, &ue);
@@ -422,9 +422,9 @@ line_delwordcursor(void)
memmove(&line.line[bs], &line.line[be], line.bytesiz - be);
line.bytesiz -= siz;
- line.bytepos -= siz;
+ line.bytepos = bs;
line.line[line.bytesiz] = '\0';
- line.utfpos -= len;
+ line.utfpos = us;
line.utflen -= len;
line.collen = colw(line.line, line.bytesiz);
line.colpos = colw(line.line, bs);
@@ -443,16 +443,16 @@ line_delwordprev(void)
line_getwordposprev(line.bytepos, line.utfpos, &bs, &us);
siz = line.bytepos - bs;
+ len = line.utfpos - us;
line.colpos -= colw(&line.line[bs], siz);
+
memmove(&line.line[bs], &line.line[line.bytepos],
line.bytesiz - line.bytepos);
- len = line.utfpos - us;
-
line.bytesiz -= siz;
- line.bytepos -= siz;
+ line.bytepos = bs;
line.line[line.bytesiz] = '\0';
- line.utfpos -= len;
+ line.utfpos = us;
line.utflen -= len;
line.collen = colw(line.line, line.bytesiz);