1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +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

@ -74,10 +74,10 @@ std::string Func_ltrim::getStrVal(rowgroup::Row& row,
// determine the size of buffer to allocate, we can be sure the wide
// char string won't be longer than:
strwclen = tstr.length(); // a guess to start with. This will be >= to the real count.
int bufsize = (strwclen + 1) * sizeof(wchar_t);
int bufsize = strwclen + 1;
// Convert the string 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);
// idb_mbstowcs can return -1 if there is bad mbs char in tstr
@ -86,8 +86,8 @@ std::string Func_ltrim::getStrVal(rowgroup::Row& row,
// Convert the trim string to wide
trimwclen = trim.length(); // A guess to start.
int trimbufsize = (trimwclen + 1) * sizeof(wchar_t);
wchar_t* wctrim = (wchar_t*)alloca(trimbufsize);
int trimbufsize = trimwclen + 1;
wchar_t* wctrim = new wchar_t[trimbufsize];
size_t trimlen = utf8::idb_mbstowcs(wctrim, trim.c_str(), trimwclen + 1);
// idb_mbstowcs can return -1 if there is bad mbs char in tstr
@ -123,7 +123,10 @@ std::string Func_ltrim::getStrVal(rowgroup::Row& row,
size_t aLen = strwclen - (aPtr - oPtr);
wstring trimmed = wstring(aPtr, aLen);
// Turn back to a string
return utf8::wstring_to_utf8(trimmed.c_str());
std::string ret(utf8::wstring_to_utf8(trimmed.c_str()));
delete [] wctrim;
delete [] wcbuf;
return ret;
}