Skip to content

Commit

Permalink
Merge pull request #21 from fastly/kate/update-for-trigraphs
Browse files Browse the repository at this point in the history
Update for escaping ? to avoid emitting trigraphs
  • Loading branch information
katef authored Jun 6, 2023
2 parents 55fc8f9 + 0f85a2d commit 07e33d1
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 07e33d1

Please sign in to comment.