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:
@@ -463,11 +463,12 @@ void MainLoop::notifyDeviceData(symbol_t symbol, bool received) {
|
|||||||
m_logRawLastSymbol = symbol;
|
m_logRawLastSymbol = symbol;
|
||||||
}
|
}
|
||||||
if (symbol == SYN && m_logRawBuffer.tellp() > 0) { // flush
|
if (symbol == SYN && m_logRawBuffer.tellp() > 0) { // flush
|
||||||
|
const string bufStr = m_logRawBuffer.str();
|
||||||
|
const char* str = bufStr.c_str();
|
||||||
if (m_logRawFile) {
|
if (m_logRawFile) {
|
||||||
const char* str = m_logRawBuffer.str().c_str();
|
|
||||||
m_logRawFile->write((const unsigned char*)str, strlen(str), received, false);
|
m_logRawFile->write((const unsigned char*)str, strlen(str), received, false);
|
||||||
} else {
|
} else {
|
||||||
logNotice(lf_bus, m_logRawBuffer.str().c_str());
|
logNotice(lf_bus, str);
|
||||||
}
|
}
|
||||||
m_logRawBuffer.str("");
|
m_logRawBuffer.str("");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -775,17 +775,18 @@ result_t ValueListDataField::readSymbols(const SymbolString& input, size_t offse
|
|||||||
result_t ValueListDataField::writeSymbols(size_t offset, istringstream* input,
|
result_t ValueListDataField::writeSymbols(size_t offset, istringstream* input,
|
||||||
SymbolString* output, size_t* usedLength) const {
|
SymbolString* output, size_t* usedLength) const {
|
||||||
const NumberDataType* numType = reinterpret_cast<const NumberDataType*>(m_dataType);
|
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
|
// replacement value
|
||||||
return numType->writeRawValue(numType->getReplacement(), offset, m_length, output, usedLength);
|
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) {
|
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);
|
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
|
char* strEnd = nullptr; // fall back to raw value in input
|
||||||
unsigned int value;
|
unsigned int value;
|
||||||
value = (unsigned int)strtoul(str, &strEnd, 10);
|
value = (unsigned int)strtoul(str, &strEnd, 10);
|
||||||
|
|||||||
@@ -805,12 +805,13 @@ result_t NumberDataType::writeSymbols(size_t offset, size_t length, istringstrea
|
|||||||
SymbolString* output, size_t* usedLength) const {
|
SymbolString* output, size_t* usedLength) const {
|
||||||
unsigned int value;
|
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
|
value = m_replacement; // replacement value
|
||||||
} else if (input->str().empty()) {
|
} else if (inputStr.empty()) {
|
||||||
return RESULT_ERR_EOF; // input too short
|
return RESULT_ERR_EOF; // input too short
|
||||||
} else if (hasFlag(EXP)) { // IEEE 754 binary32
|
} else if (hasFlag(EXP)) { // IEEE 754 binary32
|
||||||
const char* str = input->str().c_str();
|
const char* str = inputStr.c_str();
|
||||||
char* strEnd = nullptr;
|
char* strEnd = nullptr;
|
||||||
double dvalue = strtod(str, &strEnd);
|
double dvalue = strtod(str, &strEnd);
|
||||||
if (strEnd == nullptr || strEnd == str || *strEnd != 0) {
|
if (strEnd == nullptr || strEnd == str || *strEnd != 0) {
|
||||||
@@ -849,7 +850,7 @@ result_t NumberDataType::writeSymbols(size_t offset, size_t length, istringstrea
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
const char* str = input->str().c_str();
|
const char* str = inputStr.c_str();
|
||||||
char* strEnd = nullptr;
|
char* strEnd = nullptr;
|
||||||
if (m_divisor == 1) {
|
if (m_divisor == 1) {
|
||||||
if (hasFlag(SIG)) {
|
if (hasFlag(SIG)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user