Fix edge case when second hex digit is NUL

This commit is contained in:
KerfuffleV2 2023-11-03 16:33:39 -06:00
parent ee311f5ca7
commit 05bbadf3a5

View file

@ -92,11 +92,11 @@ void process_escapes(std::string& input) {
case '\\': input[output_idx++] = '\\'; break;
case 'x':
// Handle \x12, etc
if (input_idx + 2 < input_len && input[input_idx + 1] != 0) {
if (input_idx + 2 < input_len) {
const char x[3] = { input[input_idx + 1], input[input_idx + 2], 0 };
char *err_p = nullptr;
const long val = std::strtol(x, &err_p, 16);
if (*err_p == 0) {
if (err_p == x + 2) {
input_idx += 2;
input[output_idx++] = char(val);
break;