fix for bad string.c_str() usage on temporary strings (seems to be problematic starting with gcc>=6.3.0, fixes #325 and #326)

This commit is contained in:
john30
2020-01-11 12:39:23 +01:00
parent 1834b59e8b
commit 3b569a01e1
3 changed files with 12 additions and 9 deletions
+4 -3
View File
@@ -775,17 +775,18 @@ result_t ValueListDataField::readSymbols(const SymbolString& input, size_t offse
result_t ValueListDataField::writeSymbols(size_t offset, istringstream* input,
SymbolString* output, size_t* usedLength) const {
const NumberDataType* numType = reinterpret_cast<const NumberDataType*>(m_dataType);
if (isIgnored() || input->str() == nullptr_VALUE) {
const string inputStr = input->str();
if (isIgnored() || inputStr == nullptr_VALUE) {
// replacement value
return numType->writeRawValue(numType->getReplacement(), offset, m_length, output, usedLength);
}
const char* str = input->str().c_str();
for (map<unsigned int, string>::const_iterator it = m_values.begin(); it != m_values.end(); ++it) {
if (it->second.compare(str) == 0) {
if (it->second == inputStr) {
return numType->writeRawValue(it->first, offset, m_length, output, usedLength);
}
}
const char* str = inputStr.c_str();
char* strEnd = nullptr; // fall back to raw value in input
unsigned int value;
value = (unsigned int)strtoul(str, &strEnd, 10);