Fix an off-by-one past-the-end buffer read in lua

Found by coverity