Thank you for your answer, I’m very glad to hear that.
I tried increasing the number but now I’m getting segmentation faults when MAXWtFld > 56
, even though there doesn’t seem to be a large memory allocation involved when MAXWtFld == 56
. I rebuilt Garfield with the -g
flag and the debugger tells me that the segfault comes from incrementing the m_wfields std::map
:
ComponentNeBem3d::Initialise:
Prepared weighting field for readout group "wire0".
1625 m_wfields[label] = id;
(gdb)
Thread 1 "forum" received signal SIGSEGV, Segmentation fault.
0x00007ffff52c658e in std::_Rb_tree_decrement(std::_Rb_tree_node_base*) () from /lib/x86_64-linux-gnu/libstdc++.so.6
I’ve attached a short example that reproduces the error for me after editing the neBEM.h header. The segfault occurs for me even if there is only one labeled primitive (size_t nWire = 1
). Please let me know if you can’t reproduce it.
forum.cpp (1.7 KB)
EDIT: I managed to find a (temporary) solution for this. After compiling my program with AddressSanitizer, I discovered a buffer overflow in the ComponentNeBem3d::InitValues()
function. In the ComponentNeBem3d.hh file (lines 322 to 326):
/* ... */
unsigned int m_optWtFldFastVol[11];
unsigned int m_optCreateWtFldFastPF[11];
unsigned int m_optReadWtFldFastPF[11];
unsigned int m_versionWtFldFV[11];
unsigned int m_nbBlocksWtFldFV[11];
/* ... */
These arrays have size 11 instead of size MAXWtFld, leading to the buffer overflow previously described. The problem has a pretty simple fix:
#include "neBEM.h" // for MAXWtFld
/* ... */
unsigned int m_optWtFldFastVol[MAXWtFld];
unsigned int m_optCreateWtFldFastPF[MAXWtFld];
unsigned int m_optReadWtFldFastPF[MAXWtFld];
unsigned int m_versionWtFldFV[MAXWtFld];
unsigned int m_nbBlocksWtFldFV[MAXWtFld];
/* ... */
This also implies in the neBEM.h
header being installed in the project’s CMAKE_INSTALL_INCLUDEDIR
Sincerely,
Gabriel