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
+3 -2
View File
@@ -463,11 +463,12 @@ void MainLoop::notifyDeviceData(symbol_t symbol, bool received) {
m_logRawLastSymbol = symbol;
}
if (symbol == SYN && m_logRawBuffer.tellp() > 0) { // flush
const string bufStr = m_logRawBuffer.str();
const char* str = bufStr.c_str();
if (m_logRawFile) {
const char* str = m_logRawBuffer.str().c_str();
m_logRawFile->write((const unsigned char*)str, strlen(str), received, false);
} else {
logNotice(lf_bus, m_logRawBuffer.str().c_str());
logNotice(lf_bus, str);
}
m_logRawBuffer.str("");
}
+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);
+5 -4
View File
@@ -805,12 +805,13 @@ result_t NumberDataType::writeSymbols(size_t offset, size_t length, istringstrea
SymbolString* output, size_t* usedLength) const {
unsigned int value;
if (!hasFlag(REQ) && (isIgnored() || input->str() == nullptr_VALUE)) {
const string inputStr = input->str();
if (!hasFlag(REQ) && (isIgnored() || inputStr == nullptr_VALUE)) {
value = m_replacement; // replacement value
} else if (input->str().empty()) {
} else if (inputStr.empty()) {
return RESULT_ERR_EOF; // input too short
} else if (hasFlag(EXP)) { // IEEE 754 binary32
const char* str = input->str().c_str();
const char* str = inputStr.c_str();
char* strEnd = nullptr;
double dvalue = strtod(str, &strEnd);
if (strEnd == nullptr || strEnd == str || *strEnd != 0) {
@@ -849,7 +850,7 @@ result_t NumberDataType::writeSymbols(size_t offset, size_t length, istringstrea
}
#endif
} else {
const char* str = input->str().c_str();
const char* str = inputStr.c_str();
char* strEnd = nullptr;
if (m_divisor == 1) {
if (hasFlag(SIG)) {