Introduction
Introduction Statistics Contact Development Disclaimer Help
do some extra checks to be safe - sob - simple output bar
git clone git://git.codemadness.org/sob
Log
Files
Refs
README
LICENSE
---
commit 44fdd353a9864ddb98cf5ef72f57936c42805038
parent f9bbf270b93c85592b54d7d2c6b4cb769feecc64
Author: Hiltjo Posthuma <[email protected]>
Date: Sat, 4 Oct 2014 12:36:16 +0000
do some extra checks to be safe
Diffstat:
M sob.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/sob.c b/sob.c
@@ -151,7 +151,7 @@ utfuntilchar(size_t *b, size_t *u, int (*f)(int), int dir)
}
} else {
- while(*u > 0) {
+ while(*u > 0 && *b > 0) {
if(f(line.line[*b - 1]))
break;
if((n = utfprevn(line.line, *b, 1)) == 0)
@@ -289,10 +289,14 @@ line_cursor_begin(void)
static void
line_cursor_prev(void)
{
+ size_t n;
+
if(line.utfpos <= 0)
return;
+ if((n = utfprevn(line.line, line.bytepos, 1)) == 0)
+ return;
- line.bytepos -= utfprevn(line.line, line.bytepos, 1);
+ line.bytepos -= n;
line.utfpos--;
line_cursor_move(line.utfpos);
}
@@ -300,10 +304,14 @@ line_cursor_prev(void)
static void
line_cursor_next(void)
{
+ size_t n;
+
if(line.utfpos >= line.utflen)
return;
- line.bytepos += utfnextn(line.line, line.bytepos, 1);
+ if((n = utfnextn(line.line, line.bytepos, 1)) == 0)
+ return;
+ line.bytepos += n;
line.utfpos++;
line_cursor_move(line.utfpos);
}
@@ -332,7 +340,8 @@ line_delcharnext(void)
if(line.utfpos == line.utflen || line.utflen <= 0)
return;
- siz = utfnextn(line.line, line.bytepos, 1);
+ if((siz = utfnextn(line.line, line.bytepos, 1)) == 0)
+ return;
memmove(&line.line[line.bytepos], &line.line[line.bytepos + siz],
line.bytesiz - line.bytepos - siz);
@@ -348,8 +357,8 @@ line_delcharprev(void)
if(line.utfpos <= 0 || line.utflen <= 0)
return;
-
- siz = utfprevn(line.line, line.bytepos, 1);
+ if((siz = utfprevn(line.line, line.bytepos, 1)) == 0)
+ return;
memmove(&line.line[line.bytepos - siz], &line.line[line.bytepos],
line.bytesiz - line.bytepos);
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.