Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle various time_t sizes in printf and scanf #100

Merged
merged 1 commit into from
Dec 29, 2024

Conversation

snogge
Copy link
Contributor

@snogge snogge commented Apr 15, 2024

The members of the timeval struct are both signed (defined by POSIX) and typically both 64 bits on a system where time_t is 64 bits. This is possible also on 32 bit systems where time_t is larger to handle the 2038 problem.

It's practically impossible to find a type and printf format that works even on all glibc systems. Play it safe and always use printf with intmax_t and explict int64_t variables for scanf.

Alternatively, we could use autoconf to figure out the sizes and printf format specifiers, but that seemed way to complicated for what we would gain.

Note that I've changes some prints from unsigned to signed, but the data types were always signed anyway and any negative values would probably have resulted in some odd-looking timestamps.

Copy link
Member

@garlick garlick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@garlick
Copy link
Member

garlick commented Dec 29, 2024

@Mergifyio rebase

The members of the timeval struct are both signed (defined by POSIX)
and typically both 64 bits on a system where time_t is 64 bits.  This
is possible also on 32 bit systems where time_t is larger to handle
the 2038 problem.

It's practically impossible to find a type and printf format that
works even on all glibc systems.  Play it safe and always use printf
with intmax_t and explict int64_t variables for scanf.
@garlick garlick force-pushed the various-time_t-size branch from f67845c to eae17bc Compare December 29, 2024 15:30
Copy link
Contributor

mergify bot commented Dec 29, 2024

rebase

⚠️ Cannot use the command rebase

⚠ The product Workflow automation needs to be activated to enable this feature.

@mergify mergify bot merged commit 131d9db into chaos:master Dec 29, 2024
5 checks passed
snogge added a commit to snogge/diod that referenced this pull request Jan 16, 2025
The members of the timeval struct are both signed (defined by POSIX)
and typically both 64 bits on a system where time_t is 64 bits.  This
is possible also on 32 bit systems where time_t is larger to handle
the 2038 problem.

It's practically impossible to find a type and printf format that
works even on all glibc systems.  Play it safe and always use printf
with intmax_t.

Upstream-Status: Submitted [chaos#100]
Signed-off-by: Ola x Nilsson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants