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 788458 - gtk+-3.22.22/gtk/updateiconcache.c:287]: (style) Array index 'i' is used before limits check.
gtk+-3.22.22/gtk/updateiconcache.c:287]: (style) Array index 'i' is used befo...
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: .General
3.22.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2017-10-03 07:58 UTC by dcb
Modified: 2017-10-04 22:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
updateiconcache: Avoid confusing loop construct (1.35 KB, patch)
2017-10-04 21:54 UTC, Daniel Boles
none Details | Review
updateiconcache: Avoid confusing loop construct (1.50 KB, patch)
2017-10-04 21:56 UTC, Daniel Boles
committed Details | Review

Description dcb 2017-10-03 07:58:01 UTC
Source code is

     while (split[i] != NULL && i < data->n_attach_points)

Maybe better code

     while (i < data->n_attach_points && split[i] != NULL)
Comment 1 Daniel Boles 2017-10-04 21:20:08 UTC
split[] is the result of g_strsplit(), which returns a NULL-terminated array. So it doesn't actually matter. The condition is confusing, though; we shouldn't need to check both of those, as they should always both be TRUE or both be FALSE.
Comment 2 Daniel Boles 2017-10-04 21:54:01 UTC
Created attachment 360932 [details] [review]
updateiconcache: Avoid confusing loop construct

n_attach_points is the result of g_strv_length(), i.e. the index at
which the string vector ends in NULL. So, by definition, when i ==
n_attach_points, string[i] == NULL, and there is no need to check for
the latter. The fact that we did appears to confuse static analysers.
Comment 3 Daniel Boles 2017-10-04 21:56:30 UTC
Created attachment 360933 [details] [review]
updateiconcache: Avoid confusing loop construct

n_attach_points is the result of g_strv_length(): the index at which the
string vector ends in NULL. So by definition, when i == n_attach_points,
string[i] == NULL, and there is no need to check for the latter. The
fact that we did appears to confuse static analysers, as the dereference
and index check were inverted from what would normally be safe. We could
reverse them, but we may as well just remove the unnecessary NULL check.
Comment 4 Daniel Boles 2017-10-04 22:03:43 UTC
Attachment 360933 [details] pushed as 512a33f - updateiconcache: Avoid confusing loop construct