GNOME Bugzilla – Bug 795026
GLib-CRITICAL **: : assertion 'str_array != NULL' failed
Last modified: 2018-04-10 10:05:34 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.
(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.
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(-)