timespec icon indicating copy to clipboard operation
timespec copied to clipboard

Possible Y2038 problem in `timespec_from_double`.

Open ian-abbott opened this issue 3 years ago • 0 comments

timespec_from_double has this initialized variable:

	struct timespec ts = {
		.tv_sec  = s,
		.tv_nsec = (s - (long)(s)) * NSEC_PER_SEC,
	};

On platforms with 32-bit long and the usual Unix time epoch of Jan 1, 1970, this will suffer from the Year 2038 problem even if the platform uses a 64-bit time_t.

The C standard declares the tv_sec member to be of type time_t, so it should be sufficient to replace the conversion (long)(s) with (time_t)(s) (assuming time_t is an integer type because the existing code already assumes that!).

ian-abbott avatar Nov 30 '21 16:11 ian-abbott