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 653987 - g_key_file_get_integer cannot interpret integer value with trailing spaces
g_key_file_get_integer cannot interpret integer value with trailing spaces
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.24.x
Other Linux
: Normal minor
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-07-05 06:06 UTC by Emmanuel Gamby
Modified: 2011-09-09 00:21 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fixes integer parsing with trailing spaces (950 bytes, patch)
2011-09-01 17:04 UTC, Kushal Das
needs-work Details | Review
Fixes integer parsing with trailing whitespaces (1.21 KB, patch)
2011-09-02 06:51 UTC, Kushal Das
committed Details | Review

Description Emmanuel Gamby 2011-07-05 06:06:37 UTC
When there are trailing spaces after the integer value but before the carrier return, g_key_file_get_integer() returns a G_KEY_FILE_ERROR_INVALID_VALUE error.

Triming the string before the conversion would increase the robustness of the parser.
Comment 1 Kushal Das 2011-09-01 17:04:39 UTC
Created attachment 195411 [details] [review]
Fixes integer parsing with trailing spaces

This following patch fixes the issue.
Comment 2 Federico Mena Quintero 2011-09-01 21:39:45 UTC
Review of attachment 195411 [details] [review]:

::: glib/gkeyfile.c
@@ +3865,3 @@
   long_value = strtol (value, &end_of_valid_int, 10);
 
+  if (*value == '\0' || *end_of_valid_int != '\0' && *end_of_valid_int != ' ')

If you mix || and && within the same expression, please clarify their precedence with parentheses.

Also, this doesn't handle trailing tabs and whitespace other than spaces.  Can you use g_ascii_isspace() instead?
Comment 3 Kushal Das 2011-09-02 06:51:54 UTC
Created attachment 195454 [details] [review]
Fixes integer parsing with trailing whitespaces

Now using g_ascii_isspace() as suggested. Mclasen also suggested to rename the variable *end_of_vaild_int to a shorter one, that change is also done here.
Comment 4 Matthias Clasen 2011-09-04 04:15:53 UTC
Review of attachment 195454 [details] [review]:

Looks good.