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.
This commit is contained in:
Vadim Zeitlin
2021-07-16 11:11:11 +02:00
parent d83368664c
commit fb21f556a7

View File

@@ -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");
}