This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix BZ17292 parse error of string auto-concatenation in printf statement


Fix BZ17292 parse error of string auto-concatenation in printf statement

Use multi part string concatenation as the format string of printf
statement will cuase following parse error:

$ /usr/bin/stap -p1 testsuite/parseok/strconcat.stp
parse error: expected ','
	saw: string 'bar' at testsuite/parseok/strconcat.stp:6:19
     source:     printf("foo " "bar" "\n")
                               ^

1 parse error.
Pass 1: parse failed.  [man error::pass1]

This fix is suggested by fche.

Signed-off-by: Hushan Jia <hushan@smartx.com>
---
 parse.cxx                       |  8 +++-----
 testsuite/parseok/strconcat.stp | 10 ++++++++++
 2 files changed, 13 insertions(+), 5 deletions(-)
 create mode 100755 testsuite/parseok/strconcat.stp

diff --git a/parse.cxx b/parse.cxx
index 37dee82..05d2696 100644
--- a/parse.cxx
+++ b/parse.cxx
@@ -3615,10 +3615,8 @@ expression* parser::parse_symbol ()
 		  // Consume and convert a format string. Agreement between the
 		  // format string and the arguments is postponed to the
 		  // typechecking phase.
-		  string tmp;
-		  expect_unknown (tok_string, tmp);
-		  fmt->raw_components = tmp;
-		  fmt->components = print_format::string_to_components (tmp);
+		  fmt->raw_components = parse_literal_string()->value;
+		  fmt->components = print_format::string_to_components (fmt->raw_components);
 		  consumed_arg = true;
 		}
 	      else if (fmt->print_with_delim)
@@ -3626,7 +3624,7 @@ expression* parser::parse_symbol ()
 		  // Consume a delimiter to separate arguments.
 		  fmt->delimiter.clear();
 		  fmt->delimiter.type = print_format::conv_literal;
-		  expect_unknown (tok_string, fmt->delimiter.literal_string);
+		  fmt->delimiter.literal_string = parse_literal_string()->value;
 		  consumed_arg = true;
 		  min_args = 2; // so that the delim is used at least once
 		}
diff --git a/testsuite/parseok/strconcat.stp b/testsuite/parseok/strconcat.stp
new file mode 100755
index 0000000..07232f5
--- /dev/null
+++ b/testsuite/parseok/strconcat.stp
@@ -0,0 +1,10 @@
+#! stap -p1
+
+probe begin {
+    s = "foo " "bar" "\n"
+    printf("%s", s)
+    printf("foo " "bar" "\n")
+    printf("foo "
+           "bar"
+           "\n")
+}
-- 
1.8.4.2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]