0001-Fix-handling-of-unsigned-char-strings-in-printf.patch 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. From 7d01859ef16e6b65bc023ad8bebfedecb088bf81 Mon Sep 17 00:00:00 2001
  2. From: Victor Zverovich <viz@fb.com>
  3. Date: Wed, 8 Apr 2020 12:32:34 -0700
  4. Subject: [PATCH] Fix handling of unsigned char strings in printf
  5. Downloaded from upstream commit
  6. https://github.com/fmtlib/fmt/commit/7d01859ef16e6b65bc023ad8bebfedecb088bf81
  7. to fix Kodi build error:
  8. https://github.com/xbmc/xbmc/issues/17629
  9. https://github.com/fmtlib/fmt/issues/1620
  10. Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
  11. ---
  12. include/fmt/core.h | 8 ++++++++
  13. test/printf-test.cc | 6 ++++++
  14. 2 files changed, 14 insertions(+)
  15. diff --git a/include/fmt/core.h b/include/fmt/core.h
  16. index 6df2875ac..dc10722bf 100644
  17. --- a/include/fmt/core.h
  18. +++ b/include/fmt/core.h
  19. @@ -972,6 +972,14 @@ template <typename Context> struct arg_mapper {
  20. static_assert(std::is_same<char_type, char>::value, "invalid string type");
  21. return reinterpret_cast<const char*>(val);
  22. }
  23. + FMT_CONSTEXPR const char* map(signed char* val) {
  24. + const auto* const_val = val;
  25. + return map(const_val);
  26. + }
  27. + FMT_CONSTEXPR const char* map(unsigned char* val) {
  28. + const auto* const_val = val;
  29. + return map(const_val);
  30. + }
  31. FMT_CONSTEXPR const void* map(void* val) { return val; }
  32. FMT_CONSTEXPR const void* map(const void* val) { return val; }
  33. diff --git a/test/printf-test.cc b/test/printf-test.cc
  34. index 5aaa27b13..545e02aab 100644
  35. --- a/test/printf-test.cc
  36. +++ b/test/printf-test.cc
  37. @@ -447,6 +447,12 @@ TEST(PrintfTest, String) {
  38. EXPECT_PRINTF(L" (null)", L"%10s", null_wstr);
  39. }
  40. +TEST(PrintfTest, UCharString) {
  41. + unsigned char str[] = "test";
  42. + unsigned char* pstr = str;
  43. + EXPECT_EQ("test", fmt::sprintf("%s", pstr));
  44. +}
  45. +
  46. TEST(PrintfTest, Pointer) {
  47. int n;
  48. void* p = &n;