g_key_file_get_boolean() return value has two meanings
The return value for g_key_file_get_boolean()
has two meanings: it is both the value found in the key file and the indicator for whether the function was successful. This means that callers cannot use the usual pattern
if (!g_key_file_get_boolean (kf, group, key, error)) {
// handle errors here
}
to handle errors. In practice, at least in the Flatpak codebase, the function tends to be used with no error checking instead of checking if (*error != NULL)
as that is cumbersome. This has the unfortunate consequence that one can set a key equal to True
(as opposed to true
) and it will be interpreted as false.
Should we instead use the return value to indicate success (in line with the documentation for GError
) and return the boolean value via a gboolean *out_value
parameter? This would of course be an ABI break if the function is named the same, so we would need to either make a different name for the new function, or implement the change at a time when the GLib SONAME is being bumped.