Skip to content

Commit

Permalink
Escape ? as a way to avoid emitting trigraphs.
Browse files Browse the repository at this point in the history
This is applicable for the inline memcmp()/strncmp() calls added recently for the vmc codegen.
  • Loading branch information
katef committed Jun 6, 2023
1 parent f932511 commit 0f85a2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/print/c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 7 additions & 0 deletions tests/retest/tests_2.tst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ R pcre
+
-xyz

# avoid generating trigraphs (!) in strncmp()/memcmp() for inlined strings
~^abc\?\?-$
+abc??-
-abc???-
-abc~
-abc

0 comments on commit 0f85a2d

Please sign in to comment.