GNOME Bugzilla – Bug 653987
g_key_file_get_integer cannot interpret integer value with trailing spaces
Last modified: 2011-09-09 00:21:30 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.
Created attachment 195411 [details] [review] Fixes integer parsing with trailing spaces This following patch fixes the issue.
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?
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.
Review of attachment 195454 [details] [review]: Looks good.