From 45ce4be77b187ee97890b175dcfc6b415f4357e2 Mon Sep 17 00:00:00 2001 From: Hushan Jia Date: Mon, 22 Dec 2014 09:08:20 -0600 Subject: [PATCH] Fix PR17292 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. --- parse.cxx | 8 +++----- testsuite/parseok/strconcat.stp | 10 ++++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 testsuite/parseok/strconcat.stp diff --git a/parse.cxx b/parse.cxx index 37dee82bf..05d26969a 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 100644 index 000000000..07232f563 --- /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") +} -- 2.43.5