1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +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

@ -56,7 +56,7 @@ std::string Func_left::getStrVal(rowgroup::Row& row,
return "";
size_t strwclen = utf8::idb_mbstowcs(0, tstr.c_str(), 0) + 1;
wchar_t* wcbuf = (wchar_t*)alloca(strwclen * sizeof(wchar_t));
wchar_t* wcbuf = new wchar_t[strwclen];
strwclen = utf8::idb_mbstowcs(wcbuf, tstr.c_str(), strwclen);
wstring str(wcbuf, strwclen);
@ -70,9 +70,12 @@ std::string Func_left::getStrVal(rowgroup::Row& row,
wstring out = str.substr(0, pos + 1);
size_t strmblen = utf8::idb_wcstombs(0, out.c_str(), 0) + 1;
char* outbuf = (char*)alloca(strmblen * sizeof(char));
char* outbuf = new char[strmblen];
strmblen = utf8::idb_wcstombs(outbuf, out.c_str(), strmblen);
return string(outbuf, strmblen);
std::string ret(outbuf, strmblen);
delete [] outbuf;
delete [] wcbuf;
return ret;
// return str.substr(0, pos+1);
}