I have narrowed it down
As others have repeatedly said, you have not narrowed down anything. You are probably seeing effects of memory corruption, and any random change in code affects what exactly breaks at that time.
The problem isn't where it breaks down. Therefore, usual strategy of narrowing down exact place of breakage and then trying to modify that place is wasted time, because the reason is totally elsewhere.
But the place which breaks can still act as a hint.
I suggest things like:
* Look at static code analysis tools
* List symbol addresses and look what is
close to the weirdly behaving variable, for over/underindexing
* do text search on memcpy and go through every single one of them, carefully checking the addresses and size parameters
* same for array indexing []
This is all tedious and slow work, but one thing is sure: wasting time in things that
definitely are not the problem is 100% waste of time.