Skip to content

std::bad_alloc on date/time formatting #2424

Description

@lkeegan

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions