[#2212] CID78400:

Better bounds-checking
[#2212] CID76125, CID76124, and CID76123:

catch bad lexical cast exception (which I am fairly sure cannot be thrown)