MEX: fix a silly off-by-one bug