Fixed escape of string

This commit is contained in:
vvaltman 2014-09-11 19:47:44 +04:00
parent 2dd006ff76
commit 302f2822dc
2 changed files with 4 additions and 3 deletions

View File

@ -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);

View File

@ -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;