]> 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)
committerLuca Bruno <lucabru@src.gnome.org>
Tue, 23 Jun 2015 11:27:10 +0000 (13:27 +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 03b228d671d4a239e75984a7e543e40ac349aa82..1666826cb2e1a144e4dba8fb74cb7ecd0d3d0596 100644 (file)
@@ -164,6 +164,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");
+}