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

Fix overflow for very big years (>2*10^9) #2551

Merged
merged 1 commit into from
Oct 19, 2021

Conversation

phprus
Copy link
Contributor

@phprus phprus commented Oct 17, 2021

Information: #2544 (comment)

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Could you add a unit test that check that we don't have an overflow?

include/fmt/chrono.h Outdated Show resolved Hide resolved
@phprus
Copy link
Contributor Author

phprus commented Oct 17, 2021

I don't know how to write a test. The algorithm requires the correct values of tm_yday and tm_wday, and they calculated is not be simple for the distant future.
I'm not sure if the strftime function for such arguments will return the correct result.

@phprus phprus force-pushed the optimize-tm-formatting-3-ub-1 branch from 52efa44 to e935b50 Compare October 17, 2021 16:47
@vitaut vitaut merged commit 7463c83 into fmtlib:master Oct 19, 2021
@vitaut
Copy link
Contributor

vitaut commented Oct 19, 2021

For future reference this was the problematic input from fuzzer:

  char tz[] = "LMT";
  auto t = std::tm{.tm_sec = 41,
                   .tm_min = 33,
                   .tm_hour = 4,
                   .tm_mday = 21,
                   .tm_mon = 1,
                   .tm_year = -1996868082,
                   .tm_wday = 6,
                   .tm_yday = 51,
                   .tm_isdst = 0,
                   .tm_gmtoff = -28378,
                   .tm_zone = tz};
  fmt::print("{:%V}", t);

@vitaut vitaut changed the title Fix overflow for very bigger years (>2*10^9) Fix overflow for very big years (>2*10^9) Oct 19, 2021
PoetaKodu pushed a commit to pacc-repo/fmt that referenced this pull request Nov 11, 2021
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