[PATCH] initialize buf2 properly

Lars Hjemli hjemli at gmail.com
Thu Apr 7 12:51:45 CEST 2011


On Wed, Apr 6, 2011 at 13:55, Julius Plenz <plenz at cis.fu-berlin.de> wrote:
> I don't see why you would want buf2 to be static in nature.

To keep the 64 bytes off the stack, but it's not a big deal.

> If you have
> a file that contains a single newline, for example, parse_date() returns
> -1. buf2 still contains the previous date's file.
>
> Consequently, if you call read_agefile() several times in a row, the
> stack might just contain the previous date still. Thus, there's a need
> to initialize it properly.

I think we should just properly check the result from parse_date():

@@ -20,7 +20,7 @@ time_t read_agefile(char *path)
        if (readfile(path, &buf, &size))
                return -1;

-       if (parse_date(buf, buf2, sizeof(buf2)))
+       if (parse_date(buf, buf2, sizeof(buf2)) > 0)
                result = strtoul(buf2, NULL, 10);
        else
                result = 0;

--
larsh




More information about the CGit mailing list