iomenu

interactive text selection menu
Log | Files | Refs | README | LICENSE

commit e62b3c99fc9a7198c96ef70e15ad84c73534c84b
parent 90c2e1d2a25f901d709d94702f4ec2229c81990a
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Wed, 29 Nov 2017 20:56:29 +0100

assign realloc directly and no need to free, we die anyway

Diffstat:
Miomenu.c | 11+++--------
1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/iomenu.c b/iomenu.c @@ -97,10 +97,8 @@ split_lines(char *buf) linec = 1; if (!(lv = linev = calloc(linec + 1, sizeof (char **)))) die("calloc"); - if (!(mv = matchv = calloc(linec + 1, sizeof (char **)))) { - free(linev); + if (!(mv = matchv = calloc(linec + 1, sizeof (char **)))) die("calloc"); - } *mv = *lv = b = buf; while ((b = strchr(b, '\n'))) { *b = '\0'; @@ -117,7 +115,7 @@ static void read_stdin(void) { size_t size, len, off; - char *buf, *b; + char *buf; size = BUFSIZ; off = 0; @@ -126,11 +124,8 @@ read_stdin(void) off += len; if (off >= size >> 1) { size <<= 1; - if (!(b = realloc(buf, size + 1))) { - free(buf); + if (!(buf = realloc(buf, size + 1))) die("realloc"); - } - buf = b; } } buf[off] = '\0';