From: Vadim Zeitlin Date: Sun, 25 May 2003 20:28:01 +0000 (+0000) Subject: fix m_Matches overflow if Compile() is called more than once (bug 742236) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/a9103a81bed5f9beefa771fd29f9b603cd8fe4ba fix m_Matches overflow if Compile() is called more than once (bug 742236) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20733 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/regex.cpp b/src/common/regex.cpp index 6f041f7680..943fc2c46b 100644 --- a/src/common/regex.cpp +++ b/src/common/regex.cpp @@ -73,17 +73,33 @@ private: // return the string containing the error message for the given err code wxString GetErrorMsg(int errorcode) const; + // init the members + void Init() + { + m_isCompiled = FALSE; + m_Matches = NULL; + m_nMatches = 0; + } + // free the RE if compiled void Free() { if ( IsValid() ) { regfree(&m_RegEx); - - m_isCompiled = FALSE; } + + delete [] m_Matches; } + // free the RE if any and reinit the members + void Reinit() + { + Free(); + Init(); + } + + // compiled RE regex_t m_RegEx; @@ -105,16 +121,12 @@ private: wxRegExImpl::wxRegExImpl() { - m_isCompiled = FALSE; - m_Matches = NULL; - m_nMatches = 0; + Init(); } wxRegExImpl::~wxRegExImpl() { Free(); - - delete [] m_Matches; } wxString wxRegExImpl::GetErrorMsg(int errorcode) const @@ -149,7 +161,7 @@ wxString wxRegExImpl::GetErrorMsg(int errorcode) const bool wxRegExImpl::Compile(const wxString& expr, int flags) { - Free(); + Reinit(); // translate our flags to regcomp() ones wxASSERT_MSG( !(flags &