Skip to content

Commit

Permalink
Fix handling of unsigned char strings in printf
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Apr 8, 2020
1 parent 63b23e7 commit 7d01859
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,14 @@ template <typename Context> struct arg_mapper {
static_assert(std::is_same<char_type, char>::value, "invalid string type");
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(const void* val) { return val; }
Expand Down
6 changes: 6 additions & 0 deletions test/printf-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,12 @@ TEST(PrintfTest, String) {
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) {
int n;
void* p = &n;
Expand Down

0 comments on commit 7d01859

Please sign in to comment.