You've already forked mariadb-columnstore-engine
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:
@ -430,9 +430,9 @@ public:
|
|||||||
struct TableAliasName
|
struct TableAliasName
|
||||||
{
|
{
|
||||||
TableAliasName (): fisColumnStore (true) {}
|
TableAliasName (): fisColumnStore (true) {}
|
||||||
TableAliasName (std::string sch, std::string tb, std::string al) :
|
TableAliasName (const std::string &sch, const std::string &tb, const std::string &al) :
|
||||||
schema (sch), table (tb), alias (al), fisColumnStore(true) {}
|
schema (sch), table (tb), alias (al), fisColumnStore(true) {}
|
||||||
TableAliasName (std::string sch, std::string tb, std::string al, std::string v) :
|
TableAliasName (const std::string &sch, const std::string &tb, const std::string &al, const std::string &v) :
|
||||||
schema (sch), table (tb), alias (al), view(v), fisColumnStore(true) {}
|
schema (sch), table (tb), alias (al), view(v), fisColumnStore(true) {}
|
||||||
std::string schema;
|
std::string schema;
|
||||||
std::string table;
|
std::string table;
|
||||||
|
@ -310,11 +310,8 @@ void pDictionaryScan::addFilter(int8_t COP, const string& value)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint8_t* s = (uint8_t*)alloca(value.size() * sizeof(uint8_t));
|
|
||||||
|
|
||||||
memcpy(s, value.data(), value.size());
|
|
||||||
fFilterString << (uint16_t) value.size();
|
fFilterString << (uint16_t) value.size();
|
||||||
fFilterString.append(s, value.size());
|
fFilterString.append((const uint8_t*)value.data(), value.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -682,7 +682,7 @@ inline bool PrimitiveProcessor::isEscapedChar(char c)
|
|||||||
int PrimitiveProcessor::convertToRegexp(idb_regex_t* regex, const p_DataValue* str)
|
int PrimitiveProcessor::convertToRegexp(idb_regex_t* regex, const p_DataValue* str)
|
||||||
{
|
{
|
||||||
//In the worst case, every char is quadrupled, plus some leading/trailing cruft...
|
//In the worst case, every char is quadrupled, plus some leading/trailing cruft...
|
||||||
char* cBuf = (char*)alloca(((4 * str->len) + 3) * sizeof(char));
|
char* cBuf = new char[(4 * str->len) + 3];
|
||||||
char c;
|
char c;
|
||||||
int i, cBufIdx = 0;
|
int i, cBufIdx = 0;
|
||||||
// translate to regexp symbols
|
// translate to regexp symbols
|
||||||
@ -763,6 +763,7 @@ int PrimitiveProcessor::convertToRegexp(idb_regex_t* regex, const p_DataValue* s
|
|||||||
regex->regex = cBuf;
|
regex->regex = cBuf;
|
||||||
#endif
|
#endif
|
||||||
regex->used = true;
|
regex->used = true;
|
||||||
|
delete [] cBuf;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ void SMLogging::log(int priority,const char *format, ...)
|
|||||||
va_copy(args2, args);
|
va_copy(args2, args);
|
||||||
vfprintf(stderr, format, args2);
|
vfprintf(stderr, format, args2);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
va_end(args2);
|
||||||
#endif
|
#endif
|
||||||
vsyslog(priority, format, args);
|
vsyslog(priority, format, args);
|
||||||
|
|
||||||
|
@ -2011,7 +2011,7 @@ int64_t DataConvert::convertColumnTimestamp(
|
|||||||
unsigned int dataOrgLen,
|
unsigned int dataOrgLen,
|
||||||
const std::string& timeZone )
|
const std::string& timeZone )
|
||||||
{
|
{
|
||||||
|
char tmbuf[64];
|
||||||
std::string dataOrgTemp = dataOrg;
|
std::string dataOrgTemp = dataOrg;
|
||||||
if (dataOrgTemp.substr(0, 19) == "0000-00-00 00:00:00")
|
if (dataOrgTemp.substr(0, 19) == "0000-00-00 00:00:00")
|
||||||
{
|
{
|
||||||
@ -2023,7 +2023,6 @@ int64_t DataConvert::convertColumnTimestamp(
|
|||||||
if (strcmp(dataOrg, "current_timestamp() ON UPDATE current_timestamp()") == 0)
|
if (strcmp(dataOrg, "current_timestamp() ON UPDATE current_timestamp()") == 0)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
char tmbuf[64];
|
|
||||||
gettimeofday(&tv, 0);
|
gettimeofday(&tv, 0);
|
||||||
MySQLTime time;
|
MySQLTime time;
|
||||||
gmtSecToMySQLTime(tv.tv_sec, time, timeZone);
|
gmtSecToMySQLTime(tv.tv_sec, time, timeZone);
|
||||||
|
@ -268,7 +268,7 @@ bool isDateValid ( int day, int month, int year)
|
|||||||
{
|
{
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
|
|
||||||
if ( year == 0 && month == 0 && year == 0 )
|
if ( day == 0 && month == 0 && year == 0 )
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1319,7 +1319,7 @@ inline void DataConvert::trimWhitespace(int64_t& charData)
|
|||||||
inline std::string DataConvert::constructRegexp(const std::string& str)
|
inline std::string DataConvert::constructRegexp(const std::string& str)
|
||||||
{
|
{
|
||||||
//In the worst case, every char is quadrupled, plus some leading/trailing cruft...
|
//In the worst case, every char is quadrupled, plus some leading/trailing cruft...
|
||||||
char* cBuf = (char*)alloca(((4 * str.length()) + 3) * sizeof(char));
|
char* cBuf = new char[(4 * str.length()) + 3];
|
||||||
char c;
|
char c;
|
||||||
uint32_t i, cBufIdx = 0;
|
uint32_t i, cBufIdx = 0;
|
||||||
// translate to regexp symbols
|
// translate to regexp symbols
|
||||||
@ -1392,7 +1392,9 @@ inline std::string DataConvert::constructRegexp(const std::string& str)
|
|||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cerr << "regexified string is " << cBuf << endl;
|
cerr << "regexified string is " << cBuf << endl;
|
||||||
#endif
|
#endif
|
||||||
return cBuf;
|
std::string ret(cBuf);
|
||||||
|
delete [] cBuf;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dataconvert
|
} // namespace dataconvert
|
||||||
|
@ -83,9 +83,9 @@ int64_t Func_char_length::getIntVal(rowgroup::Row& row,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
size_t strwclen = utf8::idb_mbstowcs(0, tstr.c_str(), 0) + 1;
|
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);
|
strwclen = utf8::idb_mbstowcs(wcbuf, tstr.c_str(), strwclen);
|
||||||
|
delete [] wcbuf;
|
||||||
return (int64_t)strwclen;
|
return (int64_t)strwclen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ string Func_concat_ws::getStrVal(Row& row,
|
|||||||
#ifdef STRCOLL_ENH__
|
#ifdef STRCOLL_ENH__
|
||||||
wstring wstr;
|
wstring wstr;
|
||||||
size_t strwclen = utf8::idb_mbstowcs(0, delim.c_str(), 0) + 1;
|
size_t strwclen = utf8::idb_mbstowcs(0, delim.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, delim.c_str(), strwclen);
|
strwclen = utf8::idb_mbstowcs(wcbuf, delim.c_str(), strwclen);
|
||||||
wstring wdelim(wcbuf, strwclen);
|
wstring wdelim(wcbuf, strwclen);
|
||||||
|
|
||||||
@ -75,14 +75,15 @@ string Func_concat_ws::getStrVal(Row& row,
|
|||||||
wstr += wdelim;
|
wstr += wdelim;
|
||||||
|
|
||||||
size_t strwclen1 = utf8::idb_mbstowcs(0, tstr.c_str(), 0) + 1;
|
size_t strwclen1 = utf8::idb_mbstowcs(0, tstr.c_str(), 0) + 1;
|
||||||
wchar_t* wcbuf1 = (wchar_t*)alloca(strwclen1 * sizeof(wchar_t));
|
wchar_t* wcbuf1 = new wchar_t[strwclen1];
|
||||||
strwclen1 = utf8::idb_mbstowcs(wcbuf1, tstr.c_str(), strwclen1);
|
strwclen1 = utf8::idb_mbstowcs(wcbuf1, tstr.c_str(), strwclen1);
|
||||||
wstring str1(wcbuf1, strwclen1);
|
wstring str1(wcbuf1, strwclen1);
|
||||||
wstr += str1;
|
wstr += str1;
|
||||||
|
delete [] wcbuf1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t strmblen = utf8::idb_wcstombs(0, wstr.c_str(), 0) + 1;
|
size_t strmblen = utf8::idb_wcstombs(0, wstr.c_str(), 0) + 1;
|
||||||
char* outbuf = (char*)alloca(strmblen * sizeof(char));
|
char* outbuf = new char[strmblen];
|
||||||
strmblen = utf8::idb_wcstombs(outbuf, wstr.c_str(), strmblen);
|
strmblen = utf8::idb_wcstombs(outbuf, wstr.c_str(), strmblen);
|
||||||
|
|
||||||
if (strmblen == 0)
|
if (strmblen == 0)
|
||||||
@ -90,7 +91,10 @@ string Func_concat_ws::getStrVal(Row& row,
|
|||||||
else
|
else
|
||||||
isNull = false;
|
isNull = false;
|
||||||
|
|
||||||
return string(outbuf, strmblen);
|
std::string ret(outbuf, strmblen);
|
||||||
|
delete [] outbuf;
|
||||||
|
delete [] wcbuf;
|
||||||
|
return ret;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
string str;
|
string str;
|
||||||
|
@ -68,7 +68,7 @@ std::string Func_lcase::getStrVal(rowgroup::Row& row,
|
|||||||
return "";
|
return "";
|
||||||
|
|
||||||
size_t strwclen = utf8::idb_mbstowcs(0, tstr.c_str(), 0) + 1;
|
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);
|
strwclen = utf8::idb_mbstowcs(wcbuf, tstr.c_str(), strwclen);
|
||||||
wstring wstr(wcbuf, strwclen);
|
wstring wstr(wcbuf, strwclen);
|
||||||
|
|
||||||
@ -76,9 +76,12 @@ std::string Func_lcase::getStrVal(rowgroup::Row& row,
|
|||||||
wstr[i] = std::towlower(wstr[i]);
|
wstr[i] = std::towlower(wstr[i]);
|
||||||
|
|
||||||
size_t strmblen = utf8::idb_wcstombs(0, wstr.c_str(), 0) + 1;
|
size_t strmblen = utf8::idb_wcstombs(0, wstr.c_str(), 0) + 1;
|
||||||
char* outbuf = (char*)alloca(strmblen * sizeof(char));
|
char* outbuf = new char[strmblen];
|
||||||
strmblen = utf8::idb_wcstombs(outbuf, wstr.c_str(), strmblen);
|
strmblen = utf8::idb_wcstombs(outbuf, wstr.c_str(), strmblen);
|
||||||
return string(outbuf, strmblen);
|
std::string ret(outbuf, strmblen);
|
||||||
|
delete [] outbuf;
|
||||||
|
delete [] wcbuf;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ std::string Func_left::getStrVal(rowgroup::Row& row,
|
|||||||
return "";
|
return "";
|
||||||
|
|
||||||
size_t strwclen = utf8::idb_mbstowcs(0, tstr.c_str(), 0) + 1;
|
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);
|
strwclen = utf8::idb_mbstowcs(wcbuf, tstr.c_str(), strwclen);
|
||||||
wstring str(wcbuf, strwclen);
|
wstring str(wcbuf, strwclen);
|
||||||
|
|
||||||
@ -70,9 +70,12 @@ std::string Func_left::getStrVal(rowgroup::Row& row,
|
|||||||
|
|
||||||
wstring out = str.substr(0, pos + 1);
|
wstring out = str.substr(0, pos + 1);
|
||||||
size_t strmblen = utf8::idb_wcstombs(0, out.c_str(), 0) + 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);
|
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);
|
// return str.substr(0, pos+1);
|
||||||
}
|
}
|
||||||
|
@ -155,10 +155,10 @@ std::string Func_lpad::getStrVal(rowgroup::Row& row,
|
|||||||
if (strwclen > len)
|
if (strwclen > len)
|
||||||
alen = strwclen;
|
alen = strwclen;
|
||||||
|
|
||||||
size_t bufsize = (alen + 1) * sizeof(wchar_t);
|
size_t bufsize = alen + 1;
|
||||||
|
|
||||||
// Convert to wide characters. Do all further work in wide characters
|
// 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);
|
strwclen = utf8::idb_mbstowcs(wcbuf, tstr.c_str(), strwclen + 1);
|
||||||
|
|
||||||
size_t strSize = strwclen; // The number of significant characters
|
size_t strSize = strwclen; // The number of significant characters
|
||||||
@ -190,8 +190,8 @@ std::string Func_lpad::getStrVal(rowgroup::Row& row,
|
|||||||
|
|
||||||
// Convert the pad string to wide
|
// Convert the pad string to wide
|
||||||
padwclen = pad->length(); // A guess to start.
|
padwclen = pad->length(); // A guess to start.
|
||||||
size_t padbufsize = (padwclen + 1) * sizeof(wchar_t);
|
size_t padbufsize = padwclen + 1;
|
||||||
wchar_t* wcpad = (wchar_t*)alloca(padbufsize);
|
wchar_t* wcpad = new wchar_t[padbufsize];
|
||||||
// padwclen+1 is for giving count for the terminating null
|
// padwclen+1 is for giving count for the terminating null
|
||||||
size_t padlen = utf8::idb_mbstowcs(wcpad, pad->c_str(), padwclen + 1);
|
size_t padlen = utf8::idb_mbstowcs(wcpad, pad->c_str(), padwclen + 1);
|
||||||
|
|
||||||
@ -234,7 +234,10 @@ std::string Func_lpad::getStrVal(rowgroup::Row& row,
|
|||||||
|
|
||||||
wstring padded = wstring(wcbuf, len);
|
wstring padded = wstring(wcbuf, len);
|
||||||
// Turn back to a string
|
// Turn back to a string
|
||||||
return utf8::wstring_to_utf8(padded.c_str());
|
std::string ret(utf8::wstring_to_utf8(padded.c_str()));
|
||||||
|
delete [] wcpad;
|
||||||
|
delete [] wcbuf;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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
|
// determine the size of buffer to allocate, we can be sure the wide
|
||||||
// char string won't be longer than:
|
// char string won't be longer than:
|
||||||
strwclen = tstr.length(); // a guess to start with. This will be >= to the real count.
|
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
|
// 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);
|
strwclen = utf8::idb_mbstowcs(wcbuf, tstr.c_str(), strwclen + 1);
|
||||||
|
|
||||||
// idb_mbstowcs can return -1 if there is bad mbs char in tstr
|
// 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
|
// Convert the trim string to wide
|
||||||
trimwclen = trim.length(); // A guess to start.
|
trimwclen = trim.length(); // A guess to start.
|
||||||
int trimbufsize = (trimwclen + 1) * sizeof(wchar_t);
|
int trimbufsize = trimwclen + 1;
|
||||||
wchar_t* wctrim = (wchar_t*)alloca(trimbufsize);
|
wchar_t* wctrim = new wchar_t[trimbufsize];
|
||||||
size_t trimlen = utf8::idb_mbstowcs(wctrim, trim.c_str(), trimwclen + 1);
|
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
|
// 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);
|
size_t aLen = strwclen - (aPtr - oPtr);
|
||||||
wstring trimmed = wstring(aPtr, aLen);
|
wstring trimmed = wstring(aPtr, aLen);
|
||||||
// Turn back to a string
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,8 +81,7 @@ std::string Func_repeat::getStrVal(rowgroup::Row& row,
|
|||||||
int size = str.length() * count;
|
int size = str.length() * count;
|
||||||
|
|
||||||
//allocate memory
|
//allocate memory
|
||||||
char* result = NULL;
|
char* result = new char[size + 1];
|
||||||
result = (char*) alloca(size * sizeof(char) + 1);
|
|
||||||
|
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
{
|
{
|
||||||
@ -97,7 +96,9 @@ std::string Func_repeat::getStrVal(rowgroup::Row& row,
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
std::string res(result);
|
||||||
|
delete [] result;
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ std::string Func_right::getStrVal(rowgroup::Row& row,
|
|||||||
|
|
||||||
size_t strwclen = utf8::idb_mbstowcs(0, tstr.c_str(), 0) + 1;
|
size_t strwclen = utf8::idb_mbstowcs(0, tstr.c_str(), 0) + 1;
|
||||||
//wchar_t wcbuf[strwclen];
|
//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);
|
strwclen = utf8::idb_mbstowcs(wcbuf, tstr.c_str(), strwclen);
|
||||||
wstring str(wcbuf, strwclen);
|
wstring str(wcbuf, strwclen);
|
||||||
|
|
||||||
@ -75,9 +75,12 @@ std::string Func_right::getStrVal(rowgroup::Row& row,
|
|||||||
wstring out = str.substr(strwclen - pos, strwclen);
|
wstring out = str.substr(strwclen - pos, strwclen);
|
||||||
size_t strmblen = utf8::idb_wcstombs(0, out.c_str(), 0) + 1;
|
size_t strmblen = utf8::idb_wcstombs(0, out.c_str(), 0) + 1;
|
||||||
//char outbuf[strmblen];
|
//char outbuf[strmblen];
|
||||||
char* outbuf = (char*)alloca(strmblen * sizeof(char));
|
char* outbuf = new char[strmblen];
|
||||||
strmblen = utf8::idb_wcstombs(outbuf, out.c_str(), 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -155,10 +155,10 @@ std::string Func_rpad::getStrVal(rowgroup::Row& row,
|
|||||||
if (strwclen > len)
|
if (strwclen > len)
|
||||||
alen = strwclen;
|
alen = strwclen;
|
||||||
|
|
||||||
int bufsize = (alen + 1) * sizeof(wchar_t);
|
int bufsize = alen + 1;
|
||||||
|
|
||||||
// Convert to wide characters. Do all further work in wide characters
|
// 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);
|
strwclen = utf8::idb_mbstowcs(wcbuf, tstr.c_str(), strwclen + 1);
|
||||||
|
|
||||||
unsigned int strSize = strwclen; // The number of significant characters
|
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
|
// Convert the pad string to wide
|
||||||
padwclen = pad->length(); // A guess to start.
|
padwclen = pad->length(); // A guess to start.
|
||||||
int padbufsize = (padwclen + 1) * sizeof(wchar_t);
|
int padbufsize = padwclen + 1;
|
||||||
wchar_t* wcpad = (wchar_t*)alloca(padbufsize);
|
wchar_t* wcpad = new wchar_t[padbufsize];
|
||||||
size_t padlen = utf8::idb_mbstowcs(wcpad, pad->c_str(), padwclen + 1);
|
size_t padlen = utf8::idb_mbstowcs(wcpad, pad->c_str(), padwclen + 1);
|
||||||
|
|
||||||
// How many chars do we need?
|
// How many chars do we need?
|
||||||
@ -221,7 +221,10 @@ std::string Func_rpad::getStrVal(rowgroup::Row& row,
|
|||||||
wstring padded = wstring(wcbuf, len);
|
wstring padded = wstring(wcbuf, len);
|
||||||
|
|
||||||
// Bug 5110 : strings were getting truncated since enough bytes not allocated.
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,10 +73,10 @@ std::string Func_rtrim::getStrVal(rowgroup::Row& row,
|
|||||||
// determine the size of buffer to allocate, we can be sure the wide
|
// determine the size of buffer to allocate, we can be sure the wide
|
||||||
// char string won't be longer than:
|
// char string won't be longer than:
|
||||||
strwclen = tstr.length(); // a guess to start with. This will be >= to the real count.
|
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
|
// 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);
|
strwclen = utf8::idb_mbstowcs(wcbuf, tstr.c_str(), strwclen + 1);
|
||||||
|
|
||||||
// utf8::idb_mbstowcs could return -1 if there is bad chars
|
// utf8::idb_mbstowcs could return -1 if there is bad chars
|
||||||
@ -85,8 +85,8 @@ std::string Func_rtrim::getStrVal(rowgroup::Row& row,
|
|||||||
|
|
||||||
// Convert the trim string to wide
|
// Convert the trim string to wide
|
||||||
trimwclen = trim.length(); // A guess to start.
|
trimwclen = trim.length(); // A guess to start.
|
||||||
int trimbufsize = (trimwclen + 1) * sizeof(wchar_t);
|
int trimbufsize = trimwclen + 1;
|
||||||
wchar_t* wctrim = (wchar_t*)alloca(trimbufsize);
|
wchar_t* wctrim = new wchar_t[trimbufsize];
|
||||||
size_t trimlen = utf8::idb_mbstowcs(wctrim, trim.c_str(), trimwclen + 1);
|
size_t trimlen = utf8::idb_mbstowcs(wctrim, trim.c_str(), trimwclen + 1);
|
||||||
|
|
||||||
// idb_mbstowcs could return -1 if there is bad chars
|
// idb_mbstowcs could return -1 if there is bad chars
|
||||||
@ -128,7 +128,10 @@ std::string Func_rtrim::getStrVal(rowgroup::Row& row,
|
|||||||
size_t aLen = strwclen - trimCnt;
|
size_t aLen = strwclen - trimCnt;
|
||||||
wstring trimmed = wstring(aPtr, aLen);
|
wstring trimmed = wstring(aPtr, aLen);
|
||||||
// Turn back to a string
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ std::string Func_substr::getStrVal(rowgroup::Row& row,
|
|||||||
return "";
|
return "";
|
||||||
|
|
||||||
size_t strwclen = utf8::idb_mbstowcs(0, tstr.c_str(), 0) + 1;
|
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);
|
strwclen = utf8::idb_mbstowcs(wcbuf, tstr.c_str(), strwclen);
|
||||||
wstring str(wcbuf, strwclen);
|
wstring str(wcbuf, strwclen);
|
||||||
|
|
||||||
@ -98,9 +98,12 @@ std::string Func_substr::getStrVal(rowgroup::Row& row,
|
|||||||
|
|
||||||
wstring out = str.substr(start, n);
|
wstring out = str.substr(start, n);
|
||||||
size_t strmblen = utf8::idb_wcstombs(0, out.c_str(), 0) + 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);
|
strmblen = utf8::idb_wcstombs(outbuf, out.c_str(), strmblen);
|
||||||
return string(outbuf, strmblen);
|
std::string ret(outbuf, strmblen);
|
||||||
|
delete [] outbuf;
|
||||||
|
delete [] wcbuf;
|
||||||
|
return ret;
|
||||||
#else
|
#else
|
||||||
const string& str = fp[0]->data()->getStrVal(row, isNull);
|
const string& str = fp[0]->data()->getStrVal(row, isNull);
|
||||||
|
|
||||||
|
@ -72,10 +72,10 @@ std::string Func_trim::getStrVal(rowgroup::Row& row,
|
|||||||
// determine the size of buffer to allocate, we can be sure the wide
|
// determine the size of buffer to allocate, we can be sure the wide
|
||||||
// char string won't be longer than:
|
// char string won't be longer than:
|
||||||
strwclen = tstr.length(); // a guess to start with. This will be >= to the real count.
|
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
|
// 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);
|
strwclen = utf8::idb_mbstowcs(wcbuf, tstr.c_str(), strwclen + 1);
|
||||||
|
|
||||||
// Bad char in mbc can return -1
|
// Bad char in mbc can return -1
|
||||||
@ -84,8 +84,8 @@ std::string Func_trim::getStrVal(rowgroup::Row& row,
|
|||||||
|
|
||||||
// Convert the trim string to wide
|
// Convert the trim string to wide
|
||||||
trimwclen = trim.length(); // A guess to start.
|
trimwclen = trim.length(); // A guess to start.
|
||||||
int trimbufsize = (trimwclen + 1) * sizeof(wchar_t);
|
int trimbufsize = trimwclen + 1;
|
||||||
wchar_t* wctrim = (wchar_t*)alloca(trimbufsize);
|
wchar_t* wctrim = new wchar_t[trimbufsize];
|
||||||
size_t trimlen = utf8::idb_mbstowcs(wctrim, trim.c_str(), trimwclen + 1);
|
size_t trimlen = utf8::idb_mbstowcs(wctrim, trim.c_str(), trimwclen + 1);
|
||||||
|
|
||||||
// Bad char in mbc can return -1
|
// Bad char in mbc can return -1
|
||||||
@ -144,7 +144,10 @@ std::string Func_trim::getStrVal(rowgroup::Row& row,
|
|||||||
size_t aLen = strwclen - trimCnt;
|
size_t aLen = strwclen - trimCnt;
|
||||||
wstring trimmed = wstring(aPtr, aLen);
|
wstring trimmed = wstring(aPtr, aLen);
|
||||||
// Turn back to a string
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ std::string Func_ucase::getStrVal(rowgroup::Row& row,
|
|||||||
return "";
|
return "";
|
||||||
|
|
||||||
size_t strwclen = utf8::idb_mbstowcs(0, tstr.c_str(), 0) + 1;
|
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);
|
strwclen = utf8::idb_mbstowcs(wcbuf, tstr.c_str(), strwclen);
|
||||||
wstring wstr(wcbuf, strwclen);
|
wstring wstr(wcbuf, strwclen);
|
||||||
|
|
||||||
@ -75,9 +75,12 @@ std::string Func_ucase::getStrVal(rowgroup::Row& row,
|
|||||||
wstr[i] = std::towupper(wstr[i]);
|
wstr[i] = std::towupper(wstr[i]);
|
||||||
|
|
||||||
size_t strmblen = utf8::idb_wcstombs(0, wstr.c_str(), 0) + 1;
|
size_t strmblen = utf8::idb_wcstombs(0, wstr.c_str(), 0) + 1;
|
||||||
char* outbuf = (char*)alloca(strmblen * sizeof(char));
|
char* outbuf = new char[strmblen];
|
||||||
strmblen = utf8::idb_wcstombs(outbuf, wstr.c_str(), strmblen);
|
strmblen = utf8::idb_wcstombs(outbuf, wstr.c_str(), strmblen);
|
||||||
return string(outbuf, strmblen);
|
std::string ret(outbuf, strmblen);
|
||||||
|
delete [] outbuf;
|
||||||
|
delete [] wcbuf;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -217,10 +217,10 @@ size_t idb_wcstombs(char* dest, const wchar_t* src, size_t max)
|
|||||||
inline
|
inline
|
||||||
std::wstring utf8_to_wstring (const std::string& str)
|
std::wstring utf8_to_wstring (const std::string& str)
|
||||||
{
|
{
|
||||||
int bufsize = (int)((str.length() + 1) * sizeof(wchar_t));
|
size_t bufsize = str.length() + 1;
|
||||||
|
|
||||||
// Convert to wide characters. Do all further work in wide characters
|
// 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];
|
||||||
// Passing +1 so that windows is happy to see extra position to place NULL
|
// Passing +1 so that windows is happy to see extra position to place NULL
|
||||||
size_t strwclen = idb_mbstowcs(wcbuf, str.c_str(), str.length() + 1);
|
size_t strwclen = idb_mbstowcs(wcbuf, str.c_str(), str.length() + 1);
|
||||||
|
|
||||||
@ -229,7 +229,10 @@ std::wstring utf8_to_wstring (const std::string& str)
|
|||||||
if ( strwclen == static_cast<size_t>(-1) )
|
if ( strwclen == static_cast<size_t>(-1) )
|
||||||
strwclen = 0;
|
strwclen = 0;
|
||||||
|
|
||||||
return std::wstring(wcbuf, strwclen);
|
std::wstring ret(wcbuf, strwclen);
|
||||||
|
|
||||||
|
delete [] wcbuf;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -237,7 +240,7 @@ std::wstring utf8_to_wstring (const std::string& str)
|
|||||||
inline
|
inline
|
||||||
std::string wstring_to_utf8 (const std::wstring& str)
|
std::string wstring_to_utf8 (const std::wstring& str)
|
||||||
{
|
{
|
||||||
char* outbuf = (char*)alloca((str.length() * MAX_UTF8_BYTES_PER_CHAR) + 1);
|
char* outbuf = new char[(str.length() * MAX_UTF8_BYTES_PER_CHAR) + 1];
|
||||||
// Passing +1 so that windows is happy to see extra position to place NULL
|
// Passing +1 so that windows is happy to see extra position to place NULL
|
||||||
size_t strmblen = idb_wcstombs(outbuf, str.c_str(), str.length() * MAX_UTF8_BYTES_PER_CHAR + 1);
|
size_t strmblen = idb_wcstombs(outbuf, str.c_str(), str.length() * MAX_UTF8_BYTES_PER_CHAR + 1);
|
||||||
|
|
||||||
@ -246,7 +249,10 @@ std::string wstring_to_utf8 (const std::wstring& str)
|
|||||||
if ( strmblen == static_cast<size_t>(-1) )
|
if ( strmblen == static_cast<size_t>(-1) )
|
||||||
strmblen = 0;
|
strmblen = 0;
|
||||||
|
|
||||||
return std::string(outbuf, strmblen);
|
std::string ret(outbuf, strmblen);
|
||||||
|
|
||||||
|
delete [] outbuf;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
|
@ -133,7 +133,7 @@ int ColumnBuffer::writeToFile(int startOffset, int writeSize, bool fillUpWEmptie
|
|||||||
|
|
||||||
if (nitems != 1)
|
if (nitems != 1)
|
||||||
{
|
{
|
||||||
delete newBuf;
|
delete [] newBuf;
|
||||||
return ERR_FILE_WRITE;
|
return ERR_FILE_WRITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ int ColumnBuffer::writeToFile(int startOffset, int writeSize, bool fillUpWEmptie
|
|||||||
Stats::stopParseEvent(WE_STATS_WRITE_COL);
|
Stats::stopParseEvent(WE_STATS_WRITE_COL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delete newBuf;
|
delete [] newBuf;
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,6 +411,7 @@ int ColumnInfoCompressed::truncateDctnryStore(
|
|||||||
fLog->logMsg( oss.str(), rc, MSGLVL_ERROR );
|
fLog->logMsg( oss.str(), rc, MSGLVL_ERROR );
|
||||||
fTruncateDctnryFileOp.closeFile( dFile );
|
fTruncateDctnryFileOp.closeFile( dFile );
|
||||||
|
|
||||||
|
delete [] pointerHdr;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user