[tz] localtime.c issue

Alan Barrett apb at cequrux.com
Mon Jul 8 21:19:27 UTC 2013


On Mon, 08 Jul 2013, Arthur David Olson wrote:
  [localtime.c]
>--- 1514,1521 ----
>      }
>      {
>          register int_fast32_t    seconds;
>
>!         seconds = tdays * SECSPERDAY + 0.5;
>          tdays = seconds / SECSPERDAY;
>          rem += seconds - tdays * SECSPERDAY;
>      }

If time_t is an integer type, then that will multiply tdays * 
SECSPERDAY using time_t arithmetic, convert to double to add 0.5, 
then convert to int_fast32_t for the assignment.  The conversion 
to and from double may lose precision, if double has less than 32 
bits of mantissa precision (but that's unlikely).

Perhaps this will work without either a compiler warning or 
potential loss of precision:

            seconds = tdays * SECSPERDAY + (time_t)0.5;

--apb (Alan Barrett)



More information about the tz mailing list