Commit 2647f4e5 authored by BRAMAS Berenger's avatar BRAMAS Berenger
Browse files

Valgrind reveals usage of temp string in text replacer (create real object to...

Valgrind reveals usage of temp string in text replacer (create real object to avoid wrong mem access)
parent 27dfcb86
......@@ -97,10 +97,11 @@ public:
int replaceAll(const char* keyStr, const ValueClass& value){
std::ostringstream stream;
stream << value;
const char* valueStr = stream.str().c_str();
const std::string streamStr = stream.str();
const char* valueStr = streamStr.c_str();
const size_t valueLength = streamStr.size();
const size_t keyLength = strlen(keyStr);
const size_t valueLength = strlen(valueStr);
int counterOccurence = 0;
size_t from = 0;
......@@ -115,9 +116,11 @@ public:
bool replaceOne(const char* keyStr, const ValueClass& value){
std::ostringstream stream;
stream << value;
const char* valueStr = stream.str().c_str();
const std::string streamStr = stream.str();
const char* valueStr = streamStr.c_str();
const size_t valueLength = streamStr.size();
return replaceCore(0, keyStr, strlen(keyStr), valueStr, strlen(valueStr)) != content.size();
return replaceCore(0, keyStr, strlen(keyStr), valueStr, valueLength) != content.size();
}
void clear(){
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment