[magma] Fix logic for determining how many buffers to copy

This could read off the end of the array. Also fix some tests so they're
more likely to detect this.

Test: hikey960:go/magma-tps#L0

Change-Id: I8d30a5126390cef0377774336b1a03ce69c18624
2 files changed