pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: mktime() problem when building print/a2ps



The other part of the puzzle: the code tries to find the maximum and the
minimum values representable as time_t, which would be for unsigned time_t
simply: (timt_t)0 and (time_t)~0, but for signed time_t are a bit more tricky
to find, something like:

 if (sizeof(time_t) == sizeof(int)) {
   time_t_min = INT_MIN;
   time_t_max = INT_MAX;
 } else if (sizeof(time_t) == sizeof(long)) {
   time_t_min = LONG_MIN;
   time_t_max = LONG_MAX;
 } ....

Error prone if none of the conditions matches.

But instead the test uses two loops invoking undefined behaviour
expecting the signed values to wrap and that wrap around to terminate
the loop.

And modern compilers and abuse of undefined behaviour do not go well together.

Martin


Home | Main Index | Thread Index | Old Index