Skip to content

Commit

Permalink
Fix formatting string_view in UTF-8 build
Browse files Browse the repository at this point in the history
Don't use string_view data directly, as this doesn't respect its length
and would use the entire rest of the string this view is based on.

Instead, make a copy of just the part corresponding in the view to
ensure that it is NUL-terminated and also use a temporary buffer to hold
it to ensure that it lives long enough.
  • Loading branch information
vadz committed Mar 28, 2023
1 parent 2b5dbd1 commit 92649ca
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions include/wx/strvararg.h
Expand Up @@ -824,11 +824,19 @@ struct wxArgNormalizerUtf8<const std::string&>
#ifdef __cpp_lib_string_view
template<>
struct wxArgNormalizerUtf8<const std::string_view&>
: public wxArgNormalizerUtf8<const char*>
{
wxArgNormalizerUtf8(const std::string_view& v,
const wxFormatString *fmt, unsigned index)
: wxArgNormalizerUtf8<const char*>(v.data(), fmt, index) {}
: m_str{v}
{
wxASSERT_ARG_TYPE( fmt, index, wxFormatString::Arg_String );
}

const char* get() const { return m_str.c_str(); }

// We need to store this string to ensure that we use a NUL-terminated
// buffer, i.e. we can't use string_view data directly.
const std::string m_str;
};
#endif // __cpp_lib_string_view

Expand Down

0 comments on commit 92649ca

Please sign in to comment.