-
Notifications
You must be signed in to change notification settings - Fork 53
Don't call g_variant_store() with NULL
#625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
A GVariant may require 0 bytes to serialize. In which case, `data_size` will be 0 and we'll call `g_malloc0 (0)` which returns `NULL`. The `data` argument of `g_variant_store` is declared as non-nullable, so we shouldn't pass it `NULL`. In older glib versions, this wasn't explicitly checked and it still transparently worked for our case because there was nothing to actually serialize. Starting from v2.84.1, a precondition was added: https://gitlab.gnome.org/GNOME/glib/-/commit/39c05b13123b12622ee2c93c170dbf20b573f6ac Let's respect the API here and stop calling the function if it's not needed. Note that `g_variant_new_from_data()` supports being passed `NULL` and 0 for the data and size arguments.
|
See also discussion in https://gitlab.gnome.org/GNOME/glib/-/issues/3675. |
|
This patch and #624 seem to disagree about what the input value is. Do we have a non-NULL |
Missed that. Replied there. |
|
Excuse me, where is "the data argument of g_variant_store declared as non-nullable"? My glib/gvariant.h from 2.84.1 does not mention it as well as the https://docs.gtk.org/glib/method.Variant.store.html documentation. The modulemd_variant_deep_copy() is a private function and it is only used when setting XMD for a module, e.g with modulemd_module_stream_v2_set_xmd(). I feel this fix needs to be accompanied with a test. |
Hmm, I'm not sure if's supposed to be rendered on that docs page, but the annotation is definitely there: https://gitlab.gnome.org/GNOME/glib/blob/490438c41624d7753f17d3c6e3eb74bcdea1c68b/glib/gvariant-core.c#L1397. And looks like it's been there for quite a while AFAICT.
That's reasonable. I don't have the cycles to add a test for this unfortunately. The way I verified this is simply that it no longer logs the assertion failure (and e.g. |
|
Thanks for the explanation. I verified your fix and pushed a test on top of this commit. I will merge it once CI finishes. |
732d483 to
9a2c6fb
Compare
A GVariant may require 0 bytes to serialize. In which case,
data_sizewill be 0 and we'll callg_malloc0 (0)which returnsNULL.The
dataargument ofg_variant_storeis declared as non-nullable, so we shouldn't pass itNULL. In older glib versions, this wasn't explicitly checked and it still transparently worked for our case because there was nothing to actually serialize. Starting from v2.84.1, a precondition was added:https://gitlab.gnome.org/GNOME/glib/-/commit/39c05b13123b12622ee2c93c170dbf20b573f6ac
Let's respect the API here and stop calling the function if it's not needed.
Note that
g_variant_new_from_data()supports being passedNULLand 0 for the data and size arguments.