Update to parsing code to handle more incorrect inputs without causing
undefined behavior.