After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 795026 - GLib-CRITICAL **: : assertion 'str_array != NULL' failed
GLib-CRITICAL **: : assertion 'str_array != NULL' failed
Status: RESOLVED NOTABUG
Product: glib
Classification: Platform
Component: general
2.56.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2018-04-06 10:07 UTC by Adrien Plazas
Modified: 2018-04-10 10:05 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Adrien Plazas 2018-04-06 10:07:10 UTC
g_strv_length() doesn't consider NULL as a valid value, even though it is a NULL-terminated empty array and it is not documented that it isn't a valid value.

I suggest to either allow NULL (the sanest option IMO) or to document that NULL isn't accepted: the only way to know that your code is wrong so far by feeding an empty array to g_strv_length() at runtime.
Comment 1 Philip Withnall 2018-04-07 20:58:07 UTC
(In reply to Adrien Plazas from comment #0)
> g_strv_length() doesn't consider NULL as a valid value, even though it is a
> NULL-terminated empty array and it is not documented that it isn't a valid
> value.

It’s not documented that NULL *is* a valid value. Unless something is documented as (nullable), you should never assume that NULL is a valid value.

NULL is not a valid NULL-terminated array. A pointer to NULL is, though. This is akin to the difference between None and [None,] in Python.

> I suggest to either allow NULL (the sanest option IMO) or to document that
> NULL isn't accepted: the only way to know that your code is wrong so far by
> feeding an empty array to g_strv_length() at runtime.

Nope, the documentation doesn’t say NULL is allowed, so it’s not allowed. I might change it to be more explicit that NULL isn’t allowed in the future though.
Comment 2 Philip Withnall 2018-04-10 10:05:34 UTC
Pushed a minor improvement to the docs:

commit b806df0ef136b17251b01d962830f49301bbed0e (HEAD -> master, origin/master, origin/HEAD)
Author: Philip Withnall <withnall@endlessm.com>
Date:   Tue Apr 10 11:04:07 2018 +0100

    gstrfuncs: Clarify that g_strv_length() does not accept NULL
    
    https://bugzilla.gnome.org/show_bug.cgi?id=795026
    
    Signed-off-by: Philip Withnall <withnall@endlessm.com>
    Reviewed-by: nobody

 glib/gstrfuncs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)