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

tests: Handle various time_t sizes in printf #124

Merged
merged 2 commits into from
Jan 17, 2025

Conversation

snogge
Copy link
Contributor

@snogge snogge commented 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.

Comment on lines 153 to 154
msg ("Created %d objects in %"PRIdMAX".%.3"PRIdMAX"s", length * files + 1,
(intmax_t)elapsed.tv_sec, (intmax_t)elapsed.tv_usec / 1000);
Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

The format specifier macros are kind of clunky to use. Are they helpful here? In other projects we've just used %jd for an intmax_t argument. In a quick spot check of linux, freebsd, and macos, I'm seeing j in all the printf(3) man pages.

Any reason not to go that way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just thought this was guaranteed to be portable. But as you say that might not be an issue for intmax_t . I can change it if you want.

Copy link
Member

Choose a reason for hiding this comment

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

If you don't mind - please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've pushed a new version using plain %jd.

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

Great, thanks!

Copy link
Contributor

mergify bot commented Jan 17, 2025

This pull request has been removed from the queue for the following reason: pull request branch update failed.

The pull request can't be updated

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.

If you want to requeue this pull request, you need to post a comment with the text: @mergifyio requeue

@garlick garlick merged commit bd0d3ac into chaos:master Jan 17, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants