Fix dumb always-invalid mistake in next_code.

So, I think I originally did this to remove a goto, but accidentally
introduced a bug wherein any code that didn't match the first mask
was invalid.

The fix is simple, at least: add a bool to mark that the mask was found
and only return an invalid code if one isn't found.