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 trunc fill character into 16bit, even for wchar_t(linux) or char32_t #4201

Closed
XZiar opened this issue Oct 15, 2024 · 1 comment
Closed

Comments

@XZiar
Copy link
Contributor

XZiar commented Oct 15, 2024

In UTF32, a code point is 4 bytes, but fmt only keeps 2 bytes when parsing it into fill:

fmt/include/fmt/base.h

Lines 800 to 825 in cc2ba8f

template <typename Char> constexpr auto fill_unit() const -> Char {
using uchar = unsigned char;
return static_cast<Char>(static_cast<uchar>(fill_data_[0]) |
(static_cast<uchar>(fill_data_[1]) << 8));
}
FMT_CONSTEXPR void set_fill(char c) {
fill_data_[0] = c;
set_fill_size(1);
}
template <typename Char>
FMT_CONSTEXPR void set_fill(basic_string_view<Char> s) {
auto size = s.size();
set_fill_size(size);
if (size == 1) {
unsigned uchar = static_cast<detail::unsigned_char<Char>>(s[0]);
fill_data_[0] = static_cast<char>(uchar);
fill_data_[1] = static_cast<char>(uchar >> 8);
return;
}
FMT_ASSERT(size <= max_fill_size, "invalid fill");
for (size_t i = 0; i < size; ++i)
fill_data_[i & 3] = static_cast<char>(s[i]);
}
};

meanwhile, UTF8 can keep 4 bytes for fill.

repro: https://godbolt.org/z/qfTKe6W6c

@vitaut
Copy link
Contributor

vitaut commented Oct 19, 2024

Fixed in 601be1c, thanks for reporting.

@vitaut vitaut closed this as completed Oct 19, 2024
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