Fix handling of unsigned char strings in printf

This commit is contained in:
Victor Zverovich 2020-04-08 12:32:34 -07:00
parent 63b23e786a
commit 7d01859ef1
2 changed files with 14 additions and 0 deletions

View File

@ -972,6 +972,14 @@ template <typename Context> struct arg_mapper {
static_assert(std::is_same<char_type, char>::value, "invalid string type"); static_assert(std::is_same<char_type, char>::value, "invalid string type");
return reinterpret_cast<const char*>(val); return reinterpret_cast<const char*>(val);
} }
FMT_CONSTEXPR const char* map(signed char* val) {
const auto* const_val = val;
return map(const_val);
}
FMT_CONSTEXPR const char* map(unsigned char* val) {
const auto* const_val = val;
return map(const_val);
}
FMT_CONSTEXPR const void* map(void* val) { return val; } FMT_CONSTEXPR const void* map(void* val) { return val; }
FMT_CONSTEXPR const void* map(const void* val) { return val; } FMT_CONSTEXPR const void* map(const void* val) { return val; }

View File

@ -447,6 +447,12 @@ TEST(PrintfTest, String) {
EXPECT_PRINTF(L" (null)", L"%10s", null_wstr); EXPECT_PRINTF(L" (null)", L"%10s", null_wstr);
} }
TEST(PrintfTest, UCharString) {
unsigned char str[] = "test";
unsigned char* pstr = str;
EXPECT_EQ("test", fmt::sprintf("%s", pstr));
}
TEST(PrintfTest, Pointer) { TEST(PrintfTest, Pointer) {
int n; int n;
void* p = &n; void* p = &n;