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

@ -65,7 +65,7 @@ std::string Func_right::getStrVal(rowgroup::Row& row,
size_t strwclen = utf8::idb_mbstowcs(0, tstr.c_str(), 0) + 1;
//wchar_t wcbuf[strwclen];
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);
@ -75,9 +75,12 @@ std::string Func_right::getStrVal(rowgroup::Row& row,
wstring out = str.substr(strwclen - pos, strwclen);
size_t strmblen = utf8::idb_wcstombs(0, out.c_str(), 0) + 1;
//char outbuf[strmblen];
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;
}