]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Do not allow assignment with incompatible pointers
authorMarc-André Lureau <marcandre.lureau@gmail.com>
Sun, 17 Jan 2010 23:42:46 +0000 (00:42 +0100)
committerJürg Billeter <j@bitron.ch>
Mon, 18 Jan 2010 22:15:09 +0000 (23:15 +0100)
That patch makes type check with pointer more strict.

Fixes bug 574486.

vala/valapointertype.vala
vapi/glib-2.0.vapi

index 76922dcc9b6b9e57f8fd0292859c588e121c7aa3..d3203f461788ebc3cce71fa6770686faf362206f 100644 (file)
@@ -62,7 +62,22 @@ public class Vala.PointerType : DataType {
        }
 
        public override bool compatible (DataType target_type) {
-               if (target_type is PointerType || (target_type.data_type != null && target_type.data_type.get_attribute ("PointerType") != null)) {
+               if (target_type is PointerType) {
+                       var tt = target_type as PointerType;
+
+                       if (tt.base_type is VoidType || base_type is VoidType) {
+                               return true;
+                       }
+
+                       /* dereference only if both types are references or not */
+                       if (base_type.is_reference_type_or_type_parameter () != tt.base_type.is_reference_type_or_type_parameter ()) {
+                               return false;
+                       }
+
+                       return base_type.compatible (tt.base_type);
+               }
+
+               if ((target_type.data_type != null && target_type.data_type.get_attribute ("PointerType") != null)) {
                        return true;
                }
 
index f4e1b61a06ba06f195aa836e37d13a045867aaff..b877a4a0e6ea2a1fd73d3ca00f2b4f8cd268cc45 100644 (file)
@@ -1007,7 +1007,7 @@ public class string {
 
                string* result = GLib.malloc0 (this.size () - ((char*) end_string - (char*) start_string) + str_size + 1);
 
-               char* dest = result;
+               char* dest = (char*) result;
 
                GLib.Memory.copy (dest, this, (char*) start_string - (char*) this);
                dest += (char*) start_string - (char*) this;