From 708c28b952353a138baddbea8fc5b3698559406e Mon Sep 17 00:00:00 2001 From: zeffy Date: Thu, 23 Jan 2020 17:28:20 -0800 Subject: [PATCH] Make sure unit isn't null before constructing a string_view from it --- include/fmt/chrono.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index b3c7455c..80cbe697 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -771,12 +771,13 @@ OutputIt format_duration_value(OutputIt out, Rep val, int precision) { template OutputIt format_duration_unit(OutputIt out) { - if (string_view unit = get_units()) { + if (const char* unit = get_units()) { + string_view s(unit); if (const_check(std::is_same())) { - utf8_to_utf16 u(unit); + utf8_to_utf16 u(s); return std::copy(u.c_str(), u.c_str() + u.size(), out); } - return std::copy(unit.begin(), unit.end(), out); + return std::copy(s.begin(), s.end(), out); } const Char num_f[]{'[', '{', '}', ']', 's', 0}; if (Period::den == 1) return format_to(out, num_f, Period::num);