You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
void wstring_to_utf8(fmt::wmemory_buffer const& w_mem_buffer, fmt::memory_buffer& mem_buffer)
{
auto remain_space = static_cast<int32_t>(mem_buffer.capacity() - mem_buffer.size());
auto bytes_needed = remain_space;
// TODO: so far utf-8 will use at most 4 bytes for a character.
if ((w_mem_buffer.size() + 1) * 4 > static_cast<size_t>(remain_space))
{
// if our given string is larger than the capacity, calculate how many bytes we need
bytes_needed = ::WideCharToMultiByte(
CP_UTF8, 0, w_mem_buffer.data(), static_cast(w_mem_buffer.size()), NULL, 0, NULL, NULL);
mem_buffer.reserve(static_cast<uint32_t>(bytes_needed + 1 + mem_buffer.size())); // +1 for EOL symbol, i.e. '\n'
I have corrected the code as below, please merge.
void wstring_to_utf8(fmt::wmemory_buffer const& w_mem_buffer, fmt::memory_buffer& mem_buffer)
{
auto remain_space = static_cast<int32_t>(mem_buffer.capacity() - mem_buffer.size());
auto bytes_needed = remain_space;
// TODO: so far utf-8 will use at most 4 bytes for a character.
if ((w_mem_buffer.size() + 1) * 4 > static_cast<size_t>(remain_space))
{
// if our given string is larger than the capacity, calculate how many bytes we need
bytes_needed = ::WideCharToMultiByte(
CP_UTF8, 0, w_mem_buffer.data(), static_cast(w_mem_buffer.size()), NULL, 0, NULL, NULL);
}
if (QUILL_UNLIKELY(bytes_needed == 0))
{
auto const error = std::error_code(GetLastError(), std::system_category());
std::ostringstream error_msg;
error_msg << "wstring_to_utf8 failed with error message "
<< """ << error.message() << "", errno "" << error.value() << """;
QUILL_THROW(QuillError{error_msg.str()});
}
// convert
bytes_needed =
::WideCharToMultiByte(CP_UTF8, 0, w_mem_buffer.data(), static_cast(w_mem_buffer.size()),
mem_buffer.data() + mem_buffer.size(), bytes_needed, NULL, NULL);
if (QUILL_UNLIKELY(bytes_needed == 0))
{
auto const error = std::error_code(GetLastError(), std::system_category());
std::ostringstream error_msg;
error_msg << "wstring_to_utf8 failed with error message "
<< """ << error.message() << "", errno "" << error.value() << """;
QUILL_THROW(QuillError{error_msg.str()});
}
// set the new size
mem_buffer.resize(static_cast<uint32_t>(bytes_needed + mem_buffer.size()));
}
The text was updated successfully, but these errors were encountered: