From 206c0727041648e9545d16b25e591880f2c58f79 Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 20 Jun 2015 03:48:43 +0300 Subject: [PATCH] cvt_data: fix escape chars --- tools/cvt_data.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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, "\""); -- 2.39.2