Re: [PATCH 5/5] log: do not segfault on gmtime errors
- From
Jeff King <peff@peff.net>
- Date
- Mar 24, 2014, 22:11 UTC
- Message-ID
- <20140324221137.GJ13728@sigill.intra.peff.net>
- In-Reply-To
- <5330ABBE.3080106@web.de>
On Mon, Mar 24, 2014 at 11:03:42PM +0100, René Scharfe wrote:
Show 7 quoted lines
> >If the result is all-zeroes, can we check for that case instead? I > >suppose that will eventually create a "trap" at midnight on January 1st > >of the year 0 (though I am not sure such a date is even meaningful, > >given the history of our calendars). > > Makes sense. That would be "Sun Jan 0 00:00:00 1900", however -- days are > 1-based and years 1900-based in struct tm.
Oh right, I was stupidly forgetting about being 1900-based.
Show 5 quoted lines
> Since a zeroth day is invalid, would this suffice:
>
> if (!tm || !tm->tm_mday) {
>
> (Yes, I'm lazy. :)That looks perfect (and I like that it is quick to check, too, since this case should be extremely rare).
-Peff