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

An Infinite loop in the time formatter #367

Closed
danpla opened this issue Aug 4, 2016 · 3 comments
Closed

An Infinite loop in the time formatter #367

danpla opened this issue Aug 4, 2016 · 3 comments

Comments

@danpla
Copy link

danpla commented Aug 4, 2016

+ has higher precedence than ?:, so this line will not expand the buffer, giving an infinite loop with long strftime results. It should be:

buffer.reserve(buffer.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH));

Simple test:

    std::string s = "{:";
    for (int i = 0; i < 30; ++i)
        s += "%c";
    s += "}\n";

    auto t = std::time(nullptr);
    fmt::print(s, *std::localtime(&t));
@danpla
Copy link
Author

danpla commented Aug 4, 2016

An excerpt from the manual:

Note that the return value 0 does not necessarily indicate an error. For example, in many locales %p yields an empty string. An empty format string will likewise yield an empty string.

Which is, again, will give an infinite loop with out of memory error. It probably makes sense to use Python's approach.

@vitaut
Copy link
Contributor

vitaut commented Aug 4, 2016

Thanks for catching these! The first issue should be fixed in 1a23f9c.

@vitaut
Copy link
Contributor

vitaut commented Aug 5, 2016

The second issue should be fixed in a5d0adf. Thanks again.

@vitaut vitaut closed this as completed Aug 5, 2016
foonathan pushed a commit that referenced this issue Oct 23, 2016
foonathan pushed a commit that referenced this issue Oct 23, 2016
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