diff --git a/include/fmt/format.h b/include/fmt/format.h index 4104d91f..b84b6a5c 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2342,9 +2342,10 @@ template FMT_CONSTEXPR auto write(OutputIt out, const Char* s, const format_specs& specs, locale_ref) -> OutputIt { - return specs.type != presentation_type::pointer - ? write(out, basic_string_view(s), specs, {}) - : write_ptr(out, bit_cast(s), &specs); + if (specs.type == presentation_type::pointer) + return write_ptr(out, bit_cast(s), &specs); + if (!s) throw_format_error("string pointer is null"); + return write(out, basic_string_view(s), specs, {}); } template (nullptr); EXPECT_THROW_MSG( - (void)fmt::format(runtime("{0}"), static_cast(nullptr)), + (void)fmt::format("{}", nullstr), + format_error, "string pointer is null"); + EXPECT_THROW_MSG( + (void)fmt::format("{:s}", nullstr), format_error, "string pointer is null"); }