From 8ee3f96960611920c9bd2f4f41bf7cfb4a2747bd Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 23 Jun 2017 12:08:50 -0700 Subject: [PATCH] Fix formatting of non-ascii unexpected characters Signed-off-by: Philip Turnbull --- src/runtime/tree.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/runtime/tree.c b/src/runtime/tree.c index 195b6260..5d8e4019 100644 --- a/src/runtime/tree.c +++ b/src/runtime/tree.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -468,13 +469,15 @@ const TSExternalTokenState *ts_tree_last_external_token_state(const Tree *tree) static size_t ts_tree__write_char_to_string(char *s, size_t n, int32_t c) { if (c == 0) return snprintf(s, n, "EOF"); + if (c == -1) + return snprintf(s, n, "INVALID"); else if (c == '\n') return snprintf(s, n, "'\\n'"); else if (c == '\t') return snprintf(s, n, "'\\t'"); else if (c == '\r') return snprintf(s, n, "'\\r'"); - else if (c < 128) + else if (0 < c && c < 128 && isprint(c)) return snprintf(s, n, "'%c'", c); else return snprintf(s, n, "%d", c);