From 302f2822dc628634696e0b8d277e13f77f3bdc5a Mon Sep 17 00:00:00 2001 From: vvaltman Date: Thu, 11 Sep 2014 19:47:44 +0400 Subject: [PATCH] Fixed escape of string --- auto-static.c | 5 +++-- generate.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/auto-static.c b/auto-static.c index cd636a9..68da3b8 100644 --- a/auto-static.c +++ b/auto-static.c @@ -381,9 +381,10 @@ static int valid_utf8_char (const char *str) { return n + 1; } -static void print_escaped_string (const char *str) { +static void print_escaped_string (const char *str, int len) { eprintf ("\""); - while (*str) { + const char *end = str + len; + while (str < end) { int n = valid_utf8_char (str); if (n < 0) { eprintf ("\\x%02x", (int)(unsigned char)*str); diff --git a/generate.c b/generate.c index 09b48c2..1f1eb49 100644 --- a/generate.c +++ b/generate.c @@ -832,7 +832,7 @@ void gen_constructor_fetch (struct tl_combinator *c) { printf (" if (l < 0 || (l >= (1 << 22) - 2)) { return -1; }\n"); printf (" memcpy (buf, fetch_str (l), l);\n"); printf (" buf[l] = 0;\n"); - printf (" print_escaped_string (buf);\n"); + printf (" print_escaped_string (buf, l);\n"); printf (" return 0;\n"); printf ("}\n"); return;