From 2a818a16b0c371977303e464bfc75ad8814a9c7a Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 15 Feb 2010 19:28:43 -0800 Subject: PR11277: Use consistent octal in quoted strings Previously, our octal escapes used variable lengths, which can lead to ambiguities. Also, 8-bit characters would only output the least digit. * runtime/string.c (_stp_text_str): Always output 3-digit octal escapes, and handle 8-bit chars more gracefully. * testsuite/systemtap.string/text_str.stp: Include an 8-bit character. * testsuite/systemtap.string/text_str.exp: Above + expect 3-digit octal. --- runtime/string.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'runtime/string.c') diff --git a/runtime/string.c b/runtime/string.c index b3f81f0e..1d4cb255 100644 --- a/runtime/string.c +++ b/runtime/string.c @@ -102,12 +102,7 @@ static void _stp_text_str(char *outstr, char *in, int len, int quoted, int user) num = 2; break; default: - if (c > 077) - num = 4; - else if (c > 07) - num = 3; - else - num = 2; + num = 4; break; } @@ -144,10 +139,8 @@ static void _stp_text_str(char *outstr, char *in, int len, int quoted, int user) *out++ = '\\'; break; default: /* output octal representation */ - if (c > 077) - *out++ = to_oct_digit(c >> 6); - if (c > 07) - *out++ = to_oct_digit((c & 070) >> 3); + *out++ = to_oct_digit((c >> 6) & 03); + *out++ = to_oct_digit((c >> 3) & 07); *out++ = to_oct_digit(c & 07); break; } -- cgit