# MAXWtFld on ComponentNeBEM3d

**URL:** <https://root-forum.cern.ch/t/maxwtfld-on-componentnebem3d/63968>\
**Category:** Garfield++\
**Created:** [August 3, 2025, 3:31am UTC](https://root-forum.cern.ch/t/maxwtfld-on-componentnebem3d/63968 "2025-08-03T03:31:47Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![gabrielribcesario](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gabrielribcesario/32/38927_2.png) [@gabrielribcesario](https://root-forum.cern.ch/u/gabrielribcesario)\
**Post date:** [August 5, 2025, 7:12pm UTC](https://root-forum.cern.ch/t/maxwtfld-on-componentnebem3d/63968/4 "2025-08-05T19:12:17Z")

</div>

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`:

```auto
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](https://root-forum.cern.ch/uploads/short-url/5kwitZQMlmYF0YsOZTKEz6mKk60.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):

```auto
/* ... */
  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:

```auto
#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

---

_[View the full topic](https://root-forum.cern.ch/t/maxwtfld-on-componentnebem3d/63968)._
