]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Insert "%s" argument in printf calls with non-literal format string
authorJürg Billeter <j@bitron.ch>
Sat, 10 Oct 2009 13:31:01 +0000 (15:31 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 10 Oct 2009 13:31:01 +0000 (15:31 +0200)
vala/valamethodcall.vala

index 7c31f6e3229b6b2637078df53a7fa2ab4acf86f2..25865c69b94d2f71aa6ebcb48dbf827ff854b7e4 100644 (file)
@@ -271,6 +271,21 @@ public class Vala.MethodCall : Expression {
                        if (last_arg != null) {
                                // use last argument as format string
                                format_literal = last_arg as StringLiteral;
+                               if (format_literal == null && args.size == params.size - 1) {
+                                       // insert "%s" to avoid issues with embedded %
+                                       format_literal = new StringLiteral ("\"%s\"");
+                                       format_literal.target_type = analyzer.string_type.copy ();
+                                       argument_list.insert (args.size - 1, format_literal);
+
+                                       // recreate iterator and skip to right position
+                                       arg_it = argument_list.iterator ();
+                                       foreach (FormalParameter param in params) {
+                                               if (param.ellipsis) {
+                                                       break;
+                                               }
+                                               arg_it.next ();
+                                       }
+                               }
                        } else {
                                // use instance as format string for string.printf (...)
                                var ma = call as MemberAccess;