Hmm... Since you mention a hardcoded value works, and decrement by 4, I wonder if the size is actually not a multiple of 4 when working it out? It looks like the code might loop if it wasn't.