Invalid code cause SIGSEGV since loop variable tok2 was not checked properly