Fix for off-by-one error in cpp