Skip to content

Commit

Permalink
fmt::format fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekotekina committed Aug 26, 2015
1 parent 5fe3ea6 commit d1f31d6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Utilities/StrFmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,13 @@ namespace fmt
// fixed stack buffer for the first attempt
std::array<char, 4096> fixed_buf;

// possibly dynamically allocated buffer for additional attempts
// possibly dynamically allocated buffer for the second attempt
std::unique_ptr<char[]> buf;

// pointer to the current buffer
char* buf_addr = fixed_buf.data();

for (std::size_t buf_size = fixed_buf.size();; buf.reset(buf_addr = new char[buf_size]))
for (std::size_t buf_size = fixed_buf.size();;)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-security"
Expand All @@ -261,12 +261,12 @@ namespace fmt
throw std::runtime_error("std::snprintf() failed");
}

if (len <= buf_size)
if (len < buf_size)
{
return{ buf_addr, len };
}

buf_size = len;
buf.reset(buf_addr = new char[buf_size = len + 1]);
}
}

Expand Down

0 comments on commit d1f31d6

Please sign in to comment.