aboutsummaryrefslogtreecommitdiff
path: root/print.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-07-19 19:57:59 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-07-19 19:57:59 -0700
commitcc84c3d7916640b75ca4dc0785f9b1f417df1664 (patch)
tree81af5d71f4376154796636307c1b9e74ebd91c66 /print.c
parent711fe47a7f651f38e090c9a20ecef11feba6f705 (diff)
Made escape sequence handling stricter: no longer supporting arbitrary
characters, only special escapes like \n, hex sequences like \x0a, octal sequences like \012, and backslashes \\
Diffstat (limited to 'print.c')
-rw-r--r--print.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/print.c b/print.c
index eb5f67d..a66893b 100644
--- a/print.c
+++ b/print.c
@@ -162,12 +162,15 @@ static void _print_match(FILE *out, printer_t *pr, match_t *m)
}
continue;
}
+ const char *start = r;
char c = unescapechar(r, &r);
- (void)fputc(c, out);
- if (c == '\n') {
- ++line;
- pr->needs_line_number = 1;
- }
+ if (r > start) {
+ (void)fputc(c, out);
+ if (c == '\n') {
+ ++line;
+ pr->needs_line_number = 1;
+ }
+ } else (void)fputc('\\', out);
continue;
} else if (*r == '\n') {
(void)fputc('\n', out);