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 +