From fb21f556a70abcf5ecaad1e492dc13f2e83df7d2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 16 Jul 2021 11:11:11 +0200 Subject: [PATCH] Use wxCharBuffer instead of manual allocations in GetErrorMsg() Replace new[]/delete[] with a wxCharBuffer object. Also check for conversion failure when converting the error message to wide char string. --- src/common/regex.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/regex.cpp b/src/common/regex.cpp index 118bf0fcb3..96daab4dab 100644 --- a/src/common/regex.cpp +++ b/src/common/regex.cpp @@ -227,14 +227,14 @@ wxString wxRegExImpl::GetErrorMsg(int errorcode) const int len = wx_regerror(errorcode, &m_RegEx, NULL, 0); if ( len > 0 ) { - char* szcmbError = new char[++len]; + wxCharBuffer errbuf(len); - (void)wx_regerror(errorcode, &m_RegEx, szcmbError, len); + (void)wx_regerror(errorcode, &m_RegEx, errbuf.data(), errbuf.length()); - szError = wxConvLibc.cMB2WX(szcmbError); - delete [] szcmbError; + szError = wxConvLibc.cMB2WX(errbuf); } - else // regerror() returned 0 + + if ( szError.empty() ) // regerror() returned 0 or conversion failed { szError = _("unknown error"); }