]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: check for null value before calling g_strv_length
authorLuca Bruno <lucabru@src.gnome.org>
Tue, 23 Jun 2015 11:26:19 +0000 (13:26 +0200)
committerJürg Billeter <j@bitron.ch>
Tue, 11 Aug 2015 19:07:30 +0000 (21:07 +0200)
Fixes bug 751338

codegen/valagobjectmodule.vala
tests/Makefile.am
tests/objects/bug751338.vala [new file with mode: 0644]

index 79629afa3febe16b3c73d839843ed74243f69b3e..cc14136394f827d4eb24a79c5494f7917d0ce246 100644 (file)
@@ -333,9 +333,12 @@ public class Vala.GObjectModule : GTypeModule {
                                ccode.add_assignment (new CCodeIdentifier ("boxed"), cgetcall);
                                ccall.add_argument (new CCodeIdentifier ("boxed"));
 
+                               var cisnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeIdentifier ("boxed"), new CCodeConstant ("NULL"));
                                var cstrvlen = new CCodeFunctionCall (new CCodeIdentifier ("g_strv_length"));
                                cstrvlen.add_argument (new CCodeIdentifier ("boxed"));
-                               ccall.add_argument (cstrvlen);
+                               var ccond = new CCodeConditionalExpression (cisnull, new CCodeConstant ("0"), cstrvlen);
+
+                               ccall.add_argument (ccond);
                                ccode.add_expression (ccall);
                                ccode.close ();
                        } else {
index 343da516e70afd315b2b10040e52c5da8b0abc25..1e2d093f961781c668c03628a6acdad52613c8b5 100644 (file)
@@ -163,6 +163,7 @@ TESTS = \
        objects/bug701978.vala \
        objects/bug702736.vala \
        objects/bug702846.vala \
+       objects/bug751338.vala \
        errors/errors.vala \
        errors/bug567181.vala \
        errors/bug579101.vala \
diff --git a/tests/objects/bug751338.vala b/tests/objects/bug751338.vala
new file mode 100644 (file)
index 0000000..04bacac
--- /dev/null
@@ -0,0 +1,27 @@
+public class Foo : Object {
+       public string[]? strings {
+               get { return this._strings; }
+               set { this._strings = value; }
+       }
+
+       private string[]? _strings;
+}
+
+void main() {
+       string[]? strings;
+       var f = new Foo();
+       
+       f.set("strings", new string[]{ "foo", "bar" });
+       f.get("strings", out strings);
+       assert (strings[0] == "foo");
+       assert (strings[1] == "bar");
+       
+       f.set("strings", null);
+       f.get("strings", out strings);
+       assert(strings == null);
+       
+       f.set("strings", new string[]{ "foo", "bar" });
+       f.get("strings", out strings);
+       assert (strings[0] == "foo");
+       assert (strings[1] == "bar");
+}