diff --git a/src/libipc/imp/fmt.cpp b/src/libipc/imp/fmt.cpp index 20e2ed5..cc16821 100644 --- a/src/libipc/imp/fmt.cpp +++ b/src/libipc/imp/fmt.cpp @@ -221,8 +221,11 @@ bool to_string(fmt_context &ctx, std::string const &a) noexcept { } bool to_string(fmt_context &ctx, char const *a, span fstr) noexcept { - if (a == nullptr) return false; - return ipc::sprintf(ctx, fmt_of, fstr, "s", a); + if (a == nullptr) { + return ipc::sprintf(ctx, fmt_of, fstr, "s", ""); + } else { + return ipc::sprintf(ctx, fmt_of, fstr, "s", a); + } } bool to_string(fmt_context &ctx, char a) noexcept { diff --git a/test/imp/test_imp_fmt.cpp b/test/imp/test_imp_fmt.cpp index 40f0e4d..fe48097 100644 --- a/test/imp/test_imp_fmt.cpp +++ b/test/imp/test_imp_fmt.cpp @@ -112,11 +112,10 @@ TEST(fmt, fmt) { EXPECT_EQ(s, test); EXPECT_EQ(ipc::fmt("", 1, "", '2', "", 3.0), "123.000000"); + char const * nc = nullptr; + EXPECT_EQ(ipc::fmt(nc, 1, "", '2', "", 3.0), "123.000000"); std::string empty; EXPECT_EQ(ipc::fmt(empty, 1, "", '2', "", 3.0), "123.000000"); - EXPECT_EQ(ipc::fmt(empty, 1, empty, '2', "", 3.0), "123.000000"); - EXPECT_EQ(ipc::fmt("", 1, empty, '2', empty, 3.0), "123.000000"); - EXPECT_EQ(ipc::fmt("", 1, "", '2', empty), "12"); } namespace {