]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
glib-2.0: data of GLib.Bytes is allowed to be null 9c1542ce35ce39aecdde00e3a3353f8c4efe7a7f 131/head
authorMichael Gratton <mike@vee.net>
Thu, 25 Jun 2020 06:56:46 +0000 (16:56 +1000)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 25 Jun 2020 08:20:20 +0000 (10:20 +0200)
Ctors accepting uint8 arrays accept null as 0-sized array and the
`get_data` may return null if the size of the buffer is 0.

https://developer.gnome.org/glib/stable/glib-Byte-Arrays.html

vapi/glib-2.0.vapi

index 839ceff98f60d5c9f6e82861cf0b07a8166cfbc7..2374928c64317f3a1ef05c198f1a19968c7ee9c1 100644 (file)
@@ -5318,17 +5318,17 @@ namespace GLib {
        [Version (since = "2.32")]
        [CCode (cprefix = "g_bytes_", ref_function = "g_bytes_ref", unref_function = "g_bytes_unref", type_id = "G_TYPE_BYTES")]
        public class Bytes {
-               public Bytes ([CCode (array_length_type = "gsize")] uint8[] data);
-               public Bytes.take ([CCode (array_length_type = "gsize")] owned uint8[] data);
-               public Bytes.static ([CCode (array_length_type = "gsize")] uint8[] data);
-               public Bytes.with_free_func ([CCode (array_length_type = "gsize")] owned uint8[] data, GLib.DestroyNotify? free_func, void* user_data);
+               public Bytes ([CCode (array_length_type = "gsize")] uint8[]? data);
+               public Bytes.take ([CCode (array_length_type = "gsize")] owned uint8[]? data);
+               public Bytes.static ([CCode (array_length_type = "gsize")] uint8[]? data);
+               public Bytes.with_free_func ([CCode (array_length_type = "gsize")] owned uint8[]? data, GLib.DestroyNotify? free_func, void* user_data);
                public Bytes.from_bytes (GLib.Bytes bytes, size_t offset, size_t length);
 
                [CCode (cname = "g_bytes_new_with_free_func", simple_generics = true)]
-               public static Bytes new_with_owner<T> ([CCode (array_length_type = "gsize")] uint8[] data, [CCode (destroy_notify_pos = 1.9)] owned T? owner = null);
+               public static Bytes new_with_owner<T> ([CCode (array_length_type = "gsize")] uint8[]? data, [CCode (destroy_notify_pos = 1.9)] owned T? owner = null);
 
                [CCode (array_length_type = "gsize")]
-               public unowned uint8[] get_data ();
+               public unowned uint8[]? get_data ();
                public size_t get_size ();
                public uint hash ();
                public int compare (GLib.Bytes bytes2);
@@ -5338,7 +5338,8 @@ namespace GLib {
 
                [CCode (cname = "_vala_g_bytes_get")]
                public uint8 get (int index) {
-                       unowned uint8[] data = this.get_data ();
+                       assert (index >= 0 && index < (int) this.get_size ());
+                       unowned uint8[] data = (!) this.get_data ();
                        return data[index];
                }