fixed possible segfault

If the data has a specific structure, it is possible to run over the bounds of the array and cause a segmentation fault.