Post author here. I wanted the code to be "as generic as possible", so I had to accept the possibility of some useful thing being at address 0.
It could not make it work reliable. No matter which barries I set, I could not understand why is it not reliable, and had to remove the modifying code in the end.
I guess I hit the issue you've described, and now I know. Thanks!