From 91acfe685234534b8f8b379031d00cd62240ce3f Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 22 Mar 2019 07:42:57 -0700 Subject: [PATCH] Fix UBSAN warning --- include/fmt/format.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 56ce8878..0d08ec2f 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -557,13 +557,22 @@ extern template int char_traits::format_float( long double value); #endif +// A workaround for std::string not having mutable data() until C++17. +template inline Char* get_data(std::basic_string& s) { + return &s[0]; +} +template +inline typename Container::value_type* get_data(Container& c) { + return c.data(); +} + template ::value)> inline typename checked::type reserve( std::back_insert_iterator& it, std::size_t n) { Container& c = internal::get_container(it); std::size_t size = c.size(); c.resize(size + n); - return make_checked(&c[size], n); + return make_checked(get_data(c) + size, n); } template