Proposed asctime-related changes
Olson, Arthur David (NIH/NCI)
olsona at dc37a.nci.nih.gov
Mon Aug 9 19:49:48 UTC 2004
> First, GCC warns about zdump.c's new signed-versus-unsigned comparisons
"timeptr->tm_wday >= sizeof ...." and similarly for tm_mon.
> The comparisons aren't needed here, since the values are guaranteed to be
in range, so the easiest fix is to remove them.
The packaged versions of localtime and gmtime always return in-range values
for tm_wday and tm_mon.
However, zdump.c might be compiled with a version of localtime or gmtime
that does something evil, so defensive programming may be in order.
Casts along the lines shown below should do the trick.
if (timeptr->tm_wday < 0 ||
timeptr->tm_wday >= (int) (sizeof wday_name / sizeof
wn = "???";
else wn = wday_name[timeptr->tm_wday];
if (timeptr->tm_mon < 0 ||
timeptr->tm_mon >= (int) (sizeof mon_name / sizeof
mn = "???";
else mn = mon_name[timeptr->tm_mon];
More information about the tz