mirror of
https://github.com/shadps4-emu/ext-fmt.git
synced 2024-11-27 11:40:26 +00:00
Fix handling of empty non-null-terminated strings
This commit is contained in:
parent
7cbb29f61e
commit
b8bd80ff28
@ -432,7 +432,7 @@ class BasicArgFormatter : public ArgVisitor<Impl, void> {
|
||||
}
|
||||
|
||||
void write(const char *value) {
|
||||
Arg::StringValue<char> str = {value, 0};
|
||||
Arg::StringValue<char> str = {value, value != 0 ? strlen(value) : 0};
|
||||
writer_.write_str(str, spec_);
|
||||
}
|
||||
|
||||
@ -842,8 +842,6 @@ void fmt::BasicWriter<Char>::write_str(
|
||||
FMT_THROW(FormatError("string pointer is null"));
|
||||
return;
|
||||
}
|
||||
if (*str_value)
|
||||
str_size = std::char_traits<StrChar>::length(str_value);
|
||||
}
|
||||
std::size_t precision = spec.precision_;
|
||||
if (spec.precision_ >= 0 && precision < str_size)
|
||||
|
@ -1649,3 +1649,12 @@ TEST(FormatTest, Enum) {
|
||||
EXPECT_EQ("TestEnum", fmt::format("{}", TestEnum()));
|
||||
EXPECT_EQ("0", fmt::format("{}", A));
|
||||
}
|
||||
|
||||
struct EmptyTest {};
|
||||
std::ostream &operator<<(std::ostream &os, EmptyTest) {
|
||||
return os << "";
|
||||
}
|
||||
|
||||
TEST(FormatTest, EmptyCustomOutput) {
|
||||
EXPECT_EQ("", fmt::format("{}", EmptyTest()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user