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

fmt::format_to_n hangs when argument length exceeds over buffer with provided size. #2028

Closed
arthurfait opened this issue Nov 17, 2020 · 2 comments

Comments

@arthurfait
Copy link

Following code fragment hangs

#include <fmt/format.h>

int main()
{
    char buff[80];
    const char *a = "111111111111111111111111111111111111111111111111111111111111111111111111111111111";
    fmt::format_to_n(std::begin(buff), 79,FMT_STRING("{} "), a);
    fmt::print("done");
    return 0;
}

Seems there is some endless loop.

Most obvious:

template <typename T>
template <typename U>
void buffer<T>::append(const U* begin, const U* end) {
  do {
    auto count = to_unsigned(end - begin);
    try_reserve(size_ + count); // << mostly nop for fixed buffers
    auto free_cap = capacity_ - size_;
    if (free_cap < count) count = free_cap;
    std::uninitialized_copy_n(begin, count, make_checked(ptr_ + size_, count));
    size_ += count;
    begin += count;
  } while (begin != end);
}
@vitaut
Copy link
Contributor

vitaut commented Nov 17, 2020

Already fixed in master (#1996).

@vitaut vitaut closed this as completed Nov 17, 2020
@arthurfait
Copy link
Author

awaiting next release

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

No branches or pull requests

2 participants