sob

Simple output bar
git clone https://git.sinitax.com/codemadness/sob
Log | Files | Refs | README | LICENSE | Upstream | sfeed.txt

commit c02257b852543ca38d39f9c2ae1654adecb398fb
parent 12656a030acf296f0b6299175f982a6eae630646
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Thu,  2 Oct 2014 21:32:13 +0000

fix crash with memmove and cols == 0

Diffstat:
Msob.c | 10++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/sob.c b/sob.c @@ -87,7 +87,8 @@ line_inserttext(const char *s) memmove(&line.line[line.pos], s, len); } else { /* insert */ - memmove(&line.line[line.pos + len], &line.line[line.pos], line.len - line.pos); + memmove(&line.line[line.pos + len], &line.line[line.pos], + line.len - line.pos); memcpy(&line.line[line.pos], s, len); } line.len += len; @@ -162,7 +163,7 @@ line_cursor_move(size_t newpos) x += len; /* linewrap */ - if(x > cols - 1) { + if(cols > 0 && x > cols - 1) { x = x % cols; y = ((newpos + len) - x) / cols; } @@ -239,7 +240,7 @@ line_delcharnext(void) return; memmove(&line.line[line.pos], &line.line[line.pos + 1], - line.line[line.len - line.pos - 1]); + line.len - line.pos - 1); line.len--; line.line[line.len] = '\0'; line_draw(); @@ -250,8 +251,9 @@ line_delcharback(void) { if(line.pos <= 0 || line.len <= 0) return; + memmove(&line.line[line.pos - 1], &line.line[line.pos], - line.line[line.len - line.pos]); + line.len - line.pos); line.len--; line.line[line.len] = '\0'; line_cursor_prev();