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

std::bad_alloc on date/time formatting #2424

Closed
lkeegan opened this issue Jul 15, 2021 · 3 comments
Closed

std::bad_alloc on date/time formatting #2424

lkeegan opened this issue Jul 15, 2021 · 3 comments

Comments

@lkeegan
Copy link

lkeegan commented Jul 15, 2021

On msys2 the following throws a std::bad_alloc exception (example, msys2 ci output):

auto t1 = std::chrono::system_clock::now();
fmt::format("{:%F %T}", t1)

The cause is that %F and %T are not supported by the underlying strftime implementation and it just returns an empty string, which fmt interprets as the buffer being too small, so it allocates more memory and repeats until the system runs out of memory. (looks like the same issue as #367)

Previously fmt had a heuristic to avoid this (a5d0adf),
which was replaced with a nice solution that (tried to) guarantee a non-empty result from strftime (#2244), but apparently an empty result is still possible.

Maybe an upper bound on the memory allocated could be added, or the heuristic could be re-instated?

@vitaut
Copy link
Contributor

vitaut commented Jul 15, 2021

This is clearly a bug in the strftime implementation, please report to the relevant project (msys?). I don't think we should reintroduce the heuristic but we could parse the format string ourselves and reject problematic specifiers as a workaround. A PR would be welcome.

@vitaut vitaut closed this as completed Jul 15, 2021
@vitaut
Copy link
Contributor

vitaut commented Jan 1, 2022

We no longer use strftime so the issue should be resolved.

@lkeegan
Copy link
Author

lkeegan commented Jan 3, 2022

That's great - thanks!

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

No branches or pull requests

2 participants