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 741024 - glist: Mention that g_list_length() is bad for checking list emptiness
glist: Mention that g_list_length() is bad for checking list emptiness
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-12-02 15:03 UTC by Philip Withnall
Modified: 2015-02-11 09:17 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
glist: Mention that g_list_length() is bad for checking list emptiness (1.69 KB, patch)
2014-12-02 15:03 UTC, Philip Withnall
committed Details | Review

Description Philip Withnall 2014-12-02 15:03:28 UTC
Minor docs addition in response to persistent problems I’ve seen in some code I’ve been reviewing.
Comment 1 Philip Withnall 2014-12-02 15:03:30 UTC
Created attachment 291994 [details] [review]
glist: Mention that g_list_length() is bad for checking list emptiness

Despite linked lists being a fairly fundamental computer science
concept, some developers insist on using:
    g_list_length (list) > 0
to determine whether a list is non-empty, rather than using:
    list != NULL

Add a comment to the documentation for g_list_length() and
g_slist_length() pointing out the better alternative in the hope that it
will prevent some of this abuse.
Comment 2 Allison Karlitskaya (desrt) 2015-02-11 01:39:42 UTC
Review of attachment 291994 [details] [review]:

Docs here are pretty simple, so no harm done by this.
Comment 3 Philip Withnall 2015-02-11 09:17:50 UTC
Attachment 291994 [details] pushed as 93f2998 - glist: Mention that g_list_length() is bad for checking list emptiness