From: notaz Date: Sat, 20 Jun 2015 00:48:43 +0000 (+0300) Subject: cvt_data: fix escape chars X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=206c0727041648e9545d16b25e591880f2c58f79;p=ia32rtools.git cvt_data: fix escape chars --- diff --git a/tools/cvt_data.c b/tools/cvt_data.c index 93c5fd0..09e7ebc 100644 --- a/tools/cvt_data.c +++ b/tools/cvt_data.c @@ -195,7 +195,7 @@ static char *escape_string(char *s) for (; *s != 0; s++) { if (*s == '"') { - strcpy(t, "\\x22"); + strcpy(t, "\\\""); t += strlen(t); continue; } @@ -206,7 +206,9 @@ static char *escape_string(char *s) } *t++ = *s; } - *t = *s; + *t++ = *s; + if (t - buf > sizeof(buf)) + aerr("string is too long\n"); return strcpy(s, buf); } @@ -691,7 +693,9 @@ int main(int argc, char *argv[]) val = parse_number(words[w]); if (val & ~0xff) aerr("bad string trailing byte?\n"); - fprintf(fout, "\\x%02lx", val); + // unfortunately \xHH is unusable - gas interprets + // things like \x27b as 0x7b, so have to use octal here + fprintf(fout, "\\%03lo", val); } } fprintf(fout, "\"");