From 8f9db3fcb8d739de5720ebe7713db3591fbe0c1b Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 12 Mar 2021 09:13:47 -0800 Subject: [PATCH] Make ubsan happy on empty format specs (#2175) --- include/fmt/format.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 5779eab471d5..5f7c96c4ab9b 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3525,11 +3525,13 @@ struct formatter FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { + auto begin = ctx.begin(), end = ctx.end(); + if (begin == end) return begin; using handler_type = detail::dynamic_specs_handler; auto type = detail::type_constant::value; detail::specs_checker handler(handler_type(specs_, ctx), type); - auto it = parse_format_specs(ctx.begin(), ctx.end(), handler); + auto it = parse_format_specs(begin, end, handler); auto eh = ctx.error_handler(); switch (type) { case detail::type::none_type: