From 2a0c98cb7a950334758ce933d2737a4f455a8b3d Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Fri, 23 Dec 2022 17:47:54 +0500 Subject: [PATCH] Fix for issue #3241 Signed-off-by: Vladislav Shchapov --- include/fmt/core.h | 2 +- test/format-test.cc | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 968466c2..83c5f786 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -863,7 +863,7 @@ template U* { if (is_constant_evaluated()) return copy_str(begin, end, out); auto size = to_unsigned(end - begin); - memcpy(out, begin, size * sizeof(U)); + if (size > 0) memcpy(out, begin, size * sizeof(U)); return out + size; } diff --git a/test/format-test.cc b/test/format-test.cc index 69e2c4d6..b71355f3 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2047,6 +2047,10 @@ TEST(format_test, to_string) { #if FMT_USE_FLOAT128 EXPECT_EQ(fmt::to_string(__float128(0.5)), "0.5"); #endif + +#if defined(FMT_USE_STRING_VIEW) && FMT_CPLUSPLUS >= 201703L + EXPECT_EQ(fmt::to_string(std::string_view()), ""); +#endif } TEST(format_test, output_iterators) {