summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKerfuffle <44031344+KerfuffleV2@users.noreply.github.com>2023-11-05 10:06:06 -0700
committerGitHub <noreply@github.com>2023-11-05 10:06:06 -0700
commitd9ccce2e339ca0396560d18b8637f2c848d72a08 (patch)
tree91152c2265794c9af4f770f13ff45e319ffb5ea7
parentbb60fd0bf6bb270744d86dd45b3a95af01b7de45 (diff)
Allow common process_escapes to handle \x sequences (#3928)
* Allow common process_escapes to handle \x sequences * Fix edge case when second hex digit is NUL
-rw-r--r--common/common.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/common/common.cpp b/common/common.cpp
index 20cc4a08..37e3ace8 100644
--- a/common/common.cpp
+++ b/common/common.cpp
@@ -90,6 +90,19 @@ void process_escapes(std::string& input) {
case '\'': input[output_idx++] = '\''; break;
case '\"': input[output_idx++] = '\"'; break;
case '\\': input[output_idx++] = '\\'; break;
+ case 'x':
+ // Handle \x12, etc
+ 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 == x + 2) {
+ input_idx += 2;
+ input[output_idx++] = char(val);
+ break;
+ }
+ // Intentionally fall through to default.
+ }
default: input[output_idx++] = '\\';
input[output_idx++] = input[input_idx]; break;
}