From e004f1d69990772b5247b82b717e0adb4a6d9877 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 7c775e95..65ffe457 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 4362c805..40405939 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) {