Skip to content

Commit 705e3f4

Browse files
dakepc42f
authored andcommitted
Fix UB introduced by copying detail::FormatListN objects. (#59)
When copying a detail::FormatListN object, the m_formatterStore must also be copied, otherwise the pointer in the parent FormatList class are possibly invalid. This addresses the segfault explained in #58. The issue arises when makeFormatList returns an object which holds a pointer to memory created for the temporary object on the stack.
1 parent 4d03ee3 commit 705e3f4

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

tinyformat.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,10 @@ class FormatListN : public FormatList
984984
TINYFORMAT_FOREACH_ARGNUM(TINYFORMAT_MAKE_FORMATLIST_CONSTRUCTOR)
985985
# undef TINYFORMAT_MAKE_FORMATLIST_CONSTRUCTOR
986986
#endif
987+
FormatListN(const FormatListN& other)
988+
: FormatList(&m_formatterStore[0], N)
989+
{ std::copy(&other.m_formatterStore[0], &other.m_formatterStore[N],
990+
&m_formatterStore[0]); }
987991

988992
private:
989993
FormatArg m_formatterStore[N];

0 commit comments

Comments
 (0)