Commit 302f2822 authored by vvaltman's avatar vvaltman

Fixed escape of string

parent 2dd006ff
...@@ -381,9 +381,10 @@ static int valid_utf8_char (const char *str) { ...@@ -381,9 +381,10 @@ static int valid_utf8_char (const char *str) {
return n + 1; return n + 1;
} }
static void print_escaped_string (const char *str) { static void print_escaped_string (const char *str, int len) {
eprintf ("\""); eprintf ("\"");
while (*str) { const char *end = str + len;
while (str < end) {
int n = valid_utf8_char (str); int n = valid_utf8_char (str);
if (n < 0) { if (n < 0) {
eprintf ("\\x%02x", (int)(unsigned char)*str); eprintf ("\\x%02x", (int)(unsigned char)*str);
......
...@@ -832,7 +832,7 @@ void gen_constructor_fetch (struct tl_combinator *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 (" if (l < 0 || (l >= (1 << 22) - 2)) { return -1; }\n");
printf (" memcpy (buf, fetch_str (l), l);\n"); printf (" memcpy (buf, fetch_str (l), l);\n");
printf (" buf[l] = 0;\n"); printf (" buf[l] = 0;\n");
printf (" print_escaped_string (buf);\n"); printf (" print_escaped_string (buf, l);\n");
printf (" return 0;\n"); printf (" return 0;\n");
printf ("}\n"); printf ("}\n");
return; return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment