fix potential memory issue for ISF/FastCaloSim
Affected class: TFCSLateralShapeParametrizationHitChain
- Old code:
Chain_t::iterator it(&chain()[m_ninit]); - New code:
const auto it = chain().begin() + m_ninit;
The original line creates an iterator by taking the address of the element at index m_ninit, which works accidentally on x86 (e.g., lxplus) even when chain() is empty and m_ninit == 0. But it’s not memory-safe—in fact, it’s undefined behavior.
On ARM64 (macOS M-series), this line segfaults when chain() is empty. This is because &chain()[m_ninit] tries to dereference a non-existent element to take its address. Even though m_ninit == 0, chain() is empty, so there is no valid element at index 0.
I checked this using GDB: the memory pointed to by &chain()[m_ninit] shows all zeroes (00 00 00 00 00 00 00 00), which indicates a null or invalid memory region.
Tagging relevant people: @jbeirer and @zhangr
