1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-06-04 21:02:13 +03:00
Andrew Hutchings 65287a0613 MCOL-1826 Fix race in FLOAT/DOUBLE to string
In the FLOAT/DOUBLE to string conversions a class global string was used
to store the result. Unfortunately it is possible for an instance of
this class to be used by multiple threads of PrimProc simultaneously.
This would cause a race and data corruption or more likely a crash.

This fix passes a string object from the caller to use instead.
2018-10-22 17:56:49 +01:00

115 lines
2.9 KiB
C++

/* Copyright (C) 2014 InfiniDB, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
/****************************************************************************
* $Id: func_insert.cpp 2477 2011-04-01 16:07:35Z rdempsey $
*
*
****************************************************************************/
#include <string>
using namespace std;
#include "functor_str.h"
#include "functioncolumn.h"
using namespace execplan;
#include "rowgroup.h"
using namespace rowgroup;
#include "joblisttypes.h"
using namespace joblist;
#include "utf8.h"
using namespace utf8;
#define STRCOLL_ENH__
namespace funcexp
{
CalpontSystemCatalog::ColType Func_insert::operationType(FunctionParm& fp, CalpontSystemCatalog::ColType& resultType)
{
// operation type is not used by this functor
return fp[0]->data()->resultType();
}
string insertStr(const string& src, int pos, int len, const string& targ)
{
int64_t strLen = static_cast<int64_t>(src.length());
if ((pos <= 0) || ((pos-1) >= strLen))
return src;
if ((len < 0) || (len > strLen))
len = strLen;
const char* srcptr = src.c_str();
advance(srcptr,pos-1,srcptr+strLen);
// srcptr now pointing to where we need to insert targ string
uint32_t srcPos = srcptr - src.c_str();
uint32_t finPos = strLen;
const char* finptr = src.c_str();
if ((strLen - (pos-1+len)) >= 0)
{
advance(finptr,(pos-1+len),finptr+strLen);
// finptr now pointing to the end of the string to replace
finPos = finptr - src.c_str();
}
string out;
out.reserve(srcPos + targ.length() + strLen-finPos + 1);
out.append( src.c_str(), srcPos );
out.append( targ.c_str(), targ.length() );
out.append( src.c_str() + finPos, strLen-finPos );
return out;
}
std::string Func_insert::getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType&)
{
string tstr;
stringValue(fp[0], row, isNull, tstr);
if (isNull)
return "";
string tnewstr;
stringValue(fp[3], row, isNull, tnewstr);
if (isNull)
return "";
int64_t pos = fp[1]->data()->getIntVal(row, isNull);
if (isNull)
return "";
int64_t len = fp[2]->data()->getIntVal(row, isNull);
if (isNull)
return "";
return insertStr( tstr, pos, len, tnewstr );
}
} // namespace funcexp
// vim:ts=4 sw=4: