Fix start index correct handling when computing length

Signed-off-by: Daniele Ricci <daniele.athome@gmail.com>