]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Don't transform an explicit "null" into a valid format-string
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 6 Dec 2017 15:11:10 +0000 (16:11 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 7 Dec 2017 13:12:01 +0000 (14:12 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=791215

tests/Makefile.am
tests/methods/bug791215.vala [new file with mode: 0644]
vala/valamethodcall.vala
vala/valaobjectcreationexpression.vala

index 554a519ab735eb2a7e84bdaa730e76f294787687..7232aa21e7ff07fc4d664988bc12db9189a17614 100644 (file)
@@ -97,6 +97,7 @@ TESTS = \
        methods/bug774060.vala \
        methods/bug775466.test \
        methods/bug781061.vala \
+       methods/bug791215.vala \
        methods/generics.vala \
        methods/printf-invalid.test \
        methods/printf-constructor.vala \
diff --git a/tests/methods/bug791215.vala b/tests/methods/bug791215.vala
new file mode 100644 (file)
index 0000000..b5e0c09
--- /dev/null
@@ -0,0 +1,8 @@
+[PrintfFormat]
+void foo_print (string? fmt, ...) {
+       assert (fmt == null);
+}
+
+void main () {
+       foo_print (null);
+}
index 444395ac3f7e7a6a47895b361f1d14d42a5ff0ae..76f2403820645612aa05a0fdb72832af6e9d8041 100644 (file)
@@ -412,7 +412,9 @@ public class Vala.MethodCall : Expression {
                // printf arguments
                if (mtype is MethodType && ((MethodType) mtype).method_symbol.printf_format) {
                        StringLiteral format_literal = null;
-                       if (last_arg != null) {
+                       if (last_arg is NullLiteral) {
+                               // do not replace explicit null
+                       } else if (last_arg != null) {
                                // use last argument as format string
                                format_literal = StringLiteral.get_format_literal (last_arg);
                                if (format_literal == null && args.size == params.size - 1) {
index 4e5a9b958277661dd0f57934cf45cc102ff325d2..e203a1a2b9b45f08d9b3faae1864d62fd2541767 100644 (file)
@@ -385,7 +385,9 @@ public class Vala.ObjectCreationExpression : Expression {
                        // printf arguments
                        if (m.printf_format) {
                                StringLiteral format_literal = null;
-                               if (last_arg != null) {
+                               if (last_arg is NullLiteral) {
+                                       // do not replace explicit null
+                               } else if (last_arg != null) {
                                        // use last argument as format string
                                        format_literal = StringLiteral.get_format_literal (last_arg);
                                        if (format_literal == null && args.size == m.get_parameters ().size - 1) {