Skip to content

Possible Y2038 problem in timespec_from_double. #6

@ian-abbott

Description

@ian-abbott

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!).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions