core dump from within asctime_r()
kre at munnari.OZ.AU
Thu Feb 18 19:59:30 UTC 2010
Date: Tue, 16 Feb 2010 17:33:28 -0500
From: "Olson, Arthur David (NIH/NCI) [E]" <olsona at dc37a.nci.nih.gov>
Message-ID: <996D816825CFEA469870126E9050D3F0B0A1C49E at NIHMLBX11.nih.gov>
| A conservative course is to memset the state structure to all
| zeroes at the top of "tzload" (as below).
That's probably overkill, tzload() can end up being called several times.
| An alternative is to change the three "malloc(sizeof *pointer)"
| calls to "calloc(1, sizeof *pointer) calls in localtime.c.
That's what the NetBSD solution was. I think that's better, clearing the
struct once, when it is allocated, is enough, and what's more, allowing
calloc() to do it means that you get the benefit of any libc private method
of getting all those 0's, rather than a loop writing a byte at a time.
(Yes, I know memset() can do better than that - but to achieve that it needs
at least a bunch of tests to handle all the odd cases - calloc() doesn't.)
| I'm feeling conservative on this one.
Yes, with that in mind, the NetBSD people also moved the init of goahead
and goback up to the start of tzload() (where you proposed putting the
memset()) to make sure they always get set correctly. That's probably
worth doing as well - make sure that tzload() (which is responsible for
setting those values) never returns without having explicitly set them.
More information about the tz