{"record":{"id":"64ec2d82821bae58","repo":"TheAlgorithms/Go","slug":"invalid-character-in-hexadecimal-string-c","errorCode":null,"errorMessage":"invalid character in hexadecimal string: %c","messagePattern":"invalid character in hexadecimal string: %c","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"conversion/hexadecimaltodecimal.go","lineNumber":51,"sourceCode":"\t\thexStr = hexStr[2:]\n\t}\n\n\t// Validate the hexadecimal string\n\tif !isValidHexadecimal(hexStr) {\n\t\treturn 0, fmt.Errorf(\"invalid hexadecimal string\")\n\t}\n\n\tvar decimalValue int64\n\tfor _, char := range hexStr {\n\t\tvar digit int64\n\t\tif char >= '0' && char <= '9' {\n\t\t\tdigit = int64(char - '0')\n\t\t} else if char >= 'A' && char <= 'F' {\n\t\t\tdigit = int64(char - 'A' + 10)\n\t\t} else if char >= 'a' && char <= 'f' {\n\t\t\tdigit = int64(char - 'a' + 10)\n\t\t} else {\n\t\t\treturn 0, fmt.Errorf(\"invalid character in hexadecimal string: %c\", char)\n\t\t}\n\t\tdecimalValue = decimalValue*16 + digit\n\t}\n\n\treturn decimalValue, nil\n}\n","sourceCodeStart":33,"sourceCodeEnd":58,"githubUrl":"https://github.com/TheAlgorithms/Go/blob/5ba447ec5ff3d1213de65b92e726ee74c5d5cc19/conversion/hexadecimaltodecimal.go#L33-L58","documentation":"Defense-in-depth inside the accumulation loop: even after the regex check, a character that maps to no digit (theoretically unreachable for ASCII input, possible for multi-byte runes) aborts conversion naming the character.","triggerScenarios":"Thrown at conversion/hexadecimaltodecimal.go:51 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Rely on the regex validation upstream; treat this as an invariant failure","Report the exact offending character to aid debugging","Log and skip rather than fail if streaming conversion is required"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5ba447ec5ff3d1213de65b92e726ee74c5d5cc19","analyzedAt":"2026-09-02T21:54:30.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}