From 0f85a2d6d1d24664b649df4b914793e9344e20f9 Mon Sep 17 00:00:00 2001 From: Kate F Date: Mon, 5 Jun 2023 18:19:12 -0700 Subject: [PATCH] Escape ? as a way to avoid emitting trigraphs. This is applicable for the inline memcmp()/strncmp() calls added recently for the vmc codegen. --- src/print/c.c | 4 +++- tests/retest/tests_2.tst | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/print/c.c b/src/print/c.c index d8765f680..a2bc2498d 100644 --- a/src/print/c.c +++ b/src/print/c.c @@ -80,9 +80,11 @@ c_escputc_str(FILE *f, const struct fsm_options *opt, char c) * Escaping '/' here is a lazy way to avoid keeping state when * emitting '*', '/', since this is used to output example strings * inside comments. + * + * Escaping '?' is a cheap way to avoid accidentally emitting trigraphs. */ - if (!isprint((unsigned char) c) || c == '/') { + if (!isprint((unsigned char) c) || c == '/' || c == '?') { return fprintf(f, "\\%03o", (unsigned char) c); } diff --git a/tests/retest/tests_2.tst b/tests/retest/tests_2.tst index fa52536d3..03011cec4 100644 --- a/tests/retest/tests_2.tst +++ b/tests/retest/tests_2.tst @@ -16,3 +16,10 @@ R pcre + -xyz +# avoid generating trigraphs (!) in strncmp()/memcmp() for inlined strings +~^abc\?\?-$ ++abc??- +-abc???- +-abc~ +-abc +