When a string attribute is fed to NDPluginPvxs, the IOC immediately segfaults. I managed to produce this error using the epics-containers image and I've included a complete example (using a compose file) showing the problem. I've also tracked down what I think is the cause.
A bit of gdb reveals the cause of the problem. The backtrace includes fromStringAttribute.
void NTNDArrayConverterPvxs::fromStringAttribute (Value destValue, NDAttribute *src)
{
const char *value;
src->getValue(src->getDataType(), (void*)&value);
destValue["value"] = std::string(value);
}
The segfault happens on the last line, but the bug is on the line above that. Asking gdb to print value reveals:
(gdb) print value
$3 = 0x6574616c756d6953 <error: Cannot access memory at address 0x6574616c756d6953>
That's a very suspicious looking pointer. In fact, the memory that should contain the value pointer now contains a string:
(gdb) x/12c &value
0x7f1690d59028: 83 'S' 105 'i' 109 'm' 117 'u' 108 'l' 97 'a' 116 't' 101 'e'
0x7f1690d59030: 100 'd' 32 ' ' 100 'd' 101 'e'
So it looks like src->getValue is overwriting the value pointer with the string data, instead of a pointer to the string data. The corresponding code in NTNDArrayConverter looks promising:
void NTNDArrayConverter::fromStringAttribute (PVStructurePtr dest, NDAttribute *src)
{
NDAttrDataType_t attrDataType;
size_t attrDataSize;
src->getValueInfo(&attrDataType, &attrDataSize);
std::vector<char> value(attrDataSize);
src->getValue(attrDataType, &value[0], attrDataSize);
Sadly I'm not confident enough to attempt a fix, but hopefully this will help out.
FYI @gilesknap
When a string attribute is fed to
NDPluginPvxs, the IOC immediately segfaults. I managed to produce this error using the epics-containers image and I've included a complete example (using a compose file) showing the problem. I've also tracked down what I think is the cause.A bit of gdb reveals the cause of the problem. The backtrace includes
fromStringAttribute.The segfault happens on the last line, but the bug is on the line above that. Asking
gdbto printvaluereveals:That's a very suspicious looking pointer. In fact, the memory that should contain the
valuepointer now contains a string:So it looks like
src->getValueis overwriting thevaluepointer with the string data, instead of a pointer to the string data. The corresponding code inNTNDArrayConverterlooks promising:Sadly I'm not confident enough to attempt a fix, but hopefully this will help out.
FYI @gilesknap