lchat

A line oriented chat front end for ii.
git clone git://git.suckless.org/lchat
Log | Files | Refs | README

commit ee4b1cfdb77b67d8e9ca491c3f2f11d9e3805851
parent 600166571bf2a893896e1fa37e1e134296b857b4
Author: Jan Klemkow <j.klemkow@wemelug.de>
Date:   Sun, 25 Oct 2015 01:55:15 +0200

fix lenght hanling

Diffstat:
Mslackline.c | 11+++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/slackline.c b/slackline.c @@ -13,7 +13,11 @@ sl_init(void) return NULL; sl->bufsize = BUFSIZ; - sl->buf = malloc(sl->bufsize); + if ((sl->buf = malloc(sl->bufsize)) == NULL) { + free(sl); + return NULL; + } + sl->buf[0] = '\0'; sl->len = 0; sl->cur = 0; @@ -44,14 +48,17 @@ sl_keystroke(struct slackline *sl, int key) sl->buf[sl->cur++] = key; sl->buf[sl->cur] = '\0'; } - + sl->len++; return 0; } /* handle ctl keys */ switch (key) { case 8: /* backspace */ + if (sl->cur == 0) + break; sl->cur--; + sl->len--; sl->buf[sl->cur] = '\0'; break; }