From: Václav Slavík Date: Thu, 24 Jun 2010 10:34:06 +0000 (+0000) Subject: Always NUL-terminate wxPrintfConvSpec::m_szFlags. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/060ec116e4ae71c6292254e7946595a734369841 Always NUL-terminate wxPrintfConvSpec::m_szFlags. The array was initialized and terminating NUL was only added in some cases. In combination with strchr() calls, this would result it incorrect calculations or even crashes. Fixed by initializing the array to zeros. This is less error-prone than fixing the few places where explicitly adding the terminating NUL was missing. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64708 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/private/wxprintf.h b/include/wx/private/wxprintf.h index 67f05f6f57..35eec0de12 100644 --- a/include/wx/private/wxprintf.h +++ b/include/wx/private/wxprintf.h @@ -201,6 +201,7 @@ void wxPrintfConvSpec::Init() m_pArgPos = m_pArgEnd = NULL; m_type = wxPAT_INVALID; + memset(m_szFlags, 0, sizeof(m_szFlags)); // this character will never be removed from m_szFlags array and // is important when calling sprintf() in wxPrintfConvSpec::Process() ! m_szFlags[0] = '%'; @@ -387,7 +388,6 @@ bool wxPrintfConvSpec::Parse(const CharType *format) case wxT('X'): CHECK_PREC m_szFlags[flagofs++] = char(ch); - m_szFlags[flagofs] = '\0'; if (ilen == 0) m_type = wxPAT_INT; else if (ilen == -1) @@ -415,7 +415,6 @@ bool wxPrintfConvSpec::Parse(const CharType *format) case wxT('G'): CHECK_PREC m_szFlags[flagofs++] = char(ch); - m_szFlags[flagofs] = '\0'; if (ilen == 2) m_type = wxPAT_LONGDOUBLE; else @@ -426,7 +425,6 @@ bool wxPrintfConvSpec::Parse(const CharType *format) case wxT('p'): m_type = wxPAT_POINTER; m_szFlags[flagofs++] = char(ch); - m_szFlags[flagofs] = '\0'; done = true; break;