summaryrefslogtreecommitdiff
path: root/sent.c
diff options
context:
space:
mode:
authorQuentin Rameau <quinq+hackers@fifth.space>2015-11-18 23:21:33 +0100
committerMarkus Teich <markus.teich@stusta.mhn.de>2015-11-18 23:26:33 +0100
commita1dcdad14fb3a8ccdc97e86cb3aa25684778819c (patch)
tree46def943c039794d0189b049de4b89980fc01a96 /sent.c
parenteac14478e949e29e442922d997f057573ddd9923 (diff)
Bail out before allocating slides if file is empty
In load() we allocated slides before checking if we actually read anything from the FILE fp and then continue with an allocated but “empty” space wich would lead to errors.
Diffstat (limited to 'sent.c')
-rw-r--r--sent.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/sent.c b/sent.c
index f7cadb6..baf6d4f 100644
--- a/sent.c
+++ b/sent.c
@@ -413,10 +413,6 @@ void load(FILE *fp)
/* read each line from fp and add it to the item list */
while (1) {
- if ((slidecount+1) * sizeof(*slides) >= size)
- if (!(slides = realloc(slides, (size += BUFSIZ))))
- die("cannot realloc %u bytes:", size);
-
/* eat consecutive empty lines */
while ((p = fgets(buf, sizeof(buf), fp)))
if (strcmp(buf, "\n") != 0 && buf[0] != '#')
@@ -424,6 +420,10 @@ void load(FILE *fp)
if (!p)
break;
+ if ((slidecount+1) * sizeof(*slides) >= size)
+ if (!(slides = realloc(slides, (size += BUFSIZ))))
+ die("cannot realloc %u bytes:", size);
+
/* read one slide */
maxlines = 0;
memset((s = &slides[slidecount]), 0, sizeof(Slide));