Fix possible infinite loop

The first draft of the loop had the offset calculation before the check
if bytes > 0...