"Clive D.W. Feather" <clive@demon.net> writes:
if ((unsigned) timeptr->tm_wday >= sizeof wday_name / sizeof wday_name[0])
makes it one comparison instead of two.
Hold on a second. Isn't this optimization invalid on hosts with padding bits where UINT_MAX == INT_MAX? On such hosts, (unsigned)-INT_MAX is 1, which is in range, even though -INT_MAX isn't in range.
Olson, Arthur David (NIH/NCI) said:
zdump.c might be compiled with a version of localtime or gmtime that does something evil,
Well, in that case all bets are off: zdump can't possibly work on systems whose localtime or gmtime functions do arbitrarily evil things. They might set tm_year to a trap representation, for example, and in that case zdump can dump core despite the redundant checking. If you prefer the check, that's fine, I suppose it won't hurt on any real host (except for performance). But could you please add a comment about it? Something like this: /* ** This range test defends against the off-chance that the system ** localtime or gmtime is buggy and returns out-of-range values. ** We don't know of any such systems, but we're playing it safe anyway. */ if (timeptr->tm_wday < 0 || timeptr->tm_wday >= (int) (sizeof wday_name / sizeof wday_name[0]))