From a0e2a643f8d28803317ee5d0af52e7447963e173 Mon Sep 17 00:00:00 2001 From: davidkep Date: Thu, 7 Nov 2019 11:17:57 -0800 Subject: [PATCH 1/2] Fix UB introduced by copying detail::FormatListN objects. --- tinyformat.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tinyformat.h b/tinyformat.h index 7162fb0..f4442af 100644 --- a/tinyformat.h +++ b/tinyformat.h @@ -984,6 +984,11 @@ class FormatListN : public FormatList TINYFORMAT_FOREACH_ARGNUM(TINYFORMAT_MAKE_FORMATLIST_CONSTRUCTOR) # undef TINYFORMAT_MAKE_FORMATLIST_CONSTRUCTOR #endif + FormatListN(const FormatListN& other) + : FormatList(&m_formatterStore[0], N) + { std::copy(const_cast(&other.m_formatterStore[0]), + const_cast(&other.m_formatterStore[N]), + &m_formatterStore[0]); } private: FormatArg m_formatterStore[N]; From 4b11acaade06dd49f0d38c6d3117a5de8d8b1bc6 Mon Sep 17 00:00:00 2001 From: davidkep Date: Thu, 7 Nov 2019 17:39:30 -0800 Subject: [PATCH 2/2] Remove unnecessary const_cast --- tinyformat.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tinyformat.h b/tinyformat.h index f4442af..af14329 100644 --- a/tinyformat.h +++ b/tinyformat.h @@ -986,8 +986,7 @@ class FormatListN : public FormatList #endif FormatListN(const FormatListN& other) : FormatList(&m_formatterStore[0], N) - { std::copy(const_cast(&other.m_formatterStore[0]), - const_cast(&other.m_formatterStore[N]), + { std::copy(&other.m_formatterStore[0], &other.m_formatterStore[N], &m_formatterStore[0]); } private: