[hackers] [sent] Bail out before allocating slides if file is empty || Quentin Rameau

From: <git_AT_suckless.org>
Date: Wed, 18 Nov 2015 23:24:46 +0100 (CET)

commit a1dcdad14fb3a8ccdc97e86cb3aa25684778819c
Author: Quentin Rameau <quinq+hackers_AT_fifth.space>
AuthorDate: Wed Nov 18 23:21:33 2015 +0100
Commit: Markus Teich <markus.teich_AT_stusta.mhn.de>
CommitDate: Wed Nov 18 23:26:33 2015 +0100

    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.

diff --git a/sent.c b/sent.c
index f7cadb6..baf6d4f 100644
--- a/sent.c
+++ b/sent.c
_AT_@ -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] != '#')
_AT_@ -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));
Received on Wed Nov 18 2015 - 23:24:46 CET

This archive was generated by hypermail 2.3.0 : Wed Nov 18 2015 - 23:36:32 CET