1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-01 06:46:55 +03:00

Fix a few cppcheck issues

Found the following:

* Potential stack explosions with alloca() usage on potentially large
strings
* Memory leaks in WriteEngineServer
* Stack usage out of scope in dataconvert
* A typo in an 'if' statement in dataconvert
This commit is contained in:
Andrew Hutchings
2019-11-20 11:49:46 +00:00
parent 0f86a3ab14
commit dba7220ad3
22 changed files with 110 additions and 68 deletions

View File

@ -155,10 +155,10 @@ std::string Func_rpad::getStrVal(rowgroup::Row& row,
if (strwclen > len)
alen = strwclen;
int bufsize = (alen + 1) * sizeof(wchar_t);
int bufsize = alen + 1;
// Convert to wide characters. Do all further work in wide characters
wchar_t* wcbuf = (wchar_t*)alloca(bufsize);
wchar_t* wcbuf = new wchar_t[bufsize];
strwclen = utf8::idb_mbstowcs(wcbuf, tstr.c_str(), strwclen + 1);
unsigned int strSize = strwclen; // The number of significant characters
@ -190,8 +190,8 @@ std::string Func_rpad::getStrVal(rowgroup::Row& row,
// Convert the pad string to wide
padwclen = pad->length(); // A guess to start.
int padbufsize = (padwclen + 1) * sizeof(wchar_t);
wchar_t* wcpad = (wchar_t*)alloca(padbufsize);
int padbufsize = padwclen + 1;
wchar_t* wcpad = new wchar_t[padbufsize];
size_t padlen = utf8::idb_mbstowcs(wcpad, pad->c_str(), padwclen + 1);
// How many chars do we need?
@ -221,7 +221,10 @@ std::string Func_rpad::getStrVal(rowgroup::Row& row,
wstring padded = wstring(wcbuf, len);
// Bug 5110 : strings were getting truncated since enough bytes not allocated.
return utf8::wstring_to_utf8(padded.c_str());
std::string ret(utf8::wstring_to_utf8(padded.c_str()));
delete [] wcpad;
delete [] wcbuf;
return ret;
}