Fix read out of bounds error in `wcs`

This fixes a theoretical bug in `wcs`, detected with valgrind.