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 610141 - gtk_assistant_get_nth_page() function fails to deliver last page when passed -1 as page number.
gtk_assistant_get_nth_page() function fails to deliver last page when passed ...
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
unspecified
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2010-02-16 15:41 UTC by Tadej Borovšak
Modified: 2010-02-23 16:25 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Simple test application that demonstrates the problem. (475 bytes, text/x-c)
2010-02-16 15:42 UTC, Tadej Borovšak
  Details
Patch that fixes this problem. (767 bytes, patch)
2010-02-16 15:44 UTC, Tadej Borovšak
none Details | Review
Updated patch (768 bytes, patch)
2010-02-16 16:19 UTC, Tadej Borovšak
none Details | Review
Added check for out-of-bounds situations. (897 bytes, patch)
2010-02-16 17:46 UTC, Tadej Borovšak
none Details | Review
Reversed sense of g_return_val_if_failt() test that has been broken in last patch. (902 bytes, patch)
2010-02-16 19:27 UTC, Tadej Borovšak
accepted-commit_now Details | Review

Description Tadej Borovšak 2010-02-16 15:41:12 UTC
Documentation on gtk_assistant_get_nth_page() states that if one passes -1 as page number, last page will be returned. Currently, passing -1 as page number will return NULL.
Comment 1 Tadej Borovšak 2010-02-16 15:42:39 UTC
Created attachment 153928 [details]
Simple test application that demonstrates the problem.
Comment 2 Tadej Borovšak 2010-02-16 15:44:01 UTC
Created attachment 153929 [details] [review]
Patch that fixes this problem.
Comment 3 Matthias Clasen 2010-02-16 16:06:06 UTC
I think you should specifically check for -1 here. After all, the docs also state that you'll get NULL for numbers which are out-of-bounds.
Comment 4 Tadej Borovšak 2010-02-16 16:19:04 UTC
Created attachment 153936 [details] [review]
Updated patch

Updated according to recommendations from Matthias.
Comment 5 Tadej Borovšak 2010-02-16 17:09:19 UTC
Just to explain why my first patch filtered all negative values and not only -1.

If only -1 is filtered, it's still possible to pass negative value to g_list_nth(), which is bad, since this function expects unsigned integer. Luckily, negative signed integers, when passed to function that expects unsigned one, produce very large numbers, which are most of the time out of bounds, but I'm not sure if this is proper way of doing it.

Second solution would be to filter page number on like this:
  page_num <  -1 => return NULL
  page_num == -1 => return last page
  page_num >  -1 && page_num < total_pages => return requested page
  page_num >= total_pages => return NULL
Comment 6 Matthias Clasen 2010-02-16 17:35:51 UTC
I would recommend adding a g_return_val_if_fail statement to check the out-of-bounds conditions.
Comment 7 Tadej Borovšak 2010-02-16 17:46:40 UTC
Created attachment 153945 [details] [review]
Added check for out-of-bounds situations.
Comment 8 Tadej Borovšak 2010-02-16 18:30:22 UTC
My last patch is bad. g_return_val_if_fail (page_num < -1, NULL) should be g_return_val_if_fail (page_num >= -1, NULL). I'll re-create the patch if everything else is OK.
Comment 9 Matthias Clasen 2010-02-16 19:20:25 UTC
Actually, loooking at g_list_nth, it already returns NULL if the given position if out of bounds, so we may not need any extra checks, strictly speaking.
Comment 10 Matthias Clasen 2010-02-16 19:21:32 UTC
But no, it only takes a guint, so better to check explicitly. Looks alright then, with the fixes sense of the test.
Comment 11 Tadej Borovšak 2010-02-16 19:27:32 UTC
Created attachment 153954 [details] [review]
Reversed sense of g_return_val_if_failt() test that has been broken in last patch.
Comment 12 Matthias Clasen 2010-02-16 19:38:16 UTC
Comment on attachment 153954 [details] [review]
Reversed sense of g_return_val_if_failt() test that has been broken in last patch.

Looks good now, thanks.
Please commit if you have access. Otherwise, I'll take care of it later.
Comment 13 Tadej Borovšak 2010-02-16 19:47:06 UTC
I don't have access, so please commit this at your convenience.
Comment 14 Christian Dywan 2010-02-17 09:07:32 UTC
> +  g_return_val_if_fail (page_num >= -1, NULL);

That is wrong according to the documentation:

"The child widget, or NULL if page_num is out of bounds."
Comment 15 Tadej Borovšak 2010-02-17 09:21:54 UTC
Would you rather replace this with with plain if clause:

  if (page_num < -1)
    return NULL;
Comment 16 Matthias Clasen 2010-02-17 15:04:39 UTC
Christian, it also says that it returns the last page for -1. 
So, what is wrong, in your opinion ?
Comment 17 Christian Dywan 2010-02-17 16:38:18 UTC
I was thinking, if the documentation states 'out of bounds' returns NULL, I assume that < -1 shouldn't raise a critical. But on second thought, passing -42 and expecting to get NULL is probably not useful in any way. So I guess you should ignore my concern.

Incidentally gtk_notebook_get_nth_page should then get a g_return_val_if_fail as well for < -1.