Code was incorrectly checking if loop variable `i` was greater than maximum data length, rather than checking current buffer pointer.
Code was incorrectly checking if loop variable `i` was greater than maximum data length, rather than checking current buffer pointer.