GNOME Bugzilla – Bug 668756
GKeyFile: allow loading from empty strings
Last modified: 2012-01-26 19:41:17 UTC
See patch.
Created attachment 206200 [details] [review] GKeyFile: allow loading from empty strings GKeyFile supports empty files and also supports loading from the string "", but will fail with a critical if you try: - explicit length == 0 - data == NULL length == 0 should always be valid, and data == NULL should be valid in the case that length == 0, so add some testcases for those and fix the code up to allow them.
This problem can be seen if you do this: dconf dump /a/ | dconf load /b/ and /a/ is empty. This pattern is a useful trick to migrate a bunch of keys.
Review of attachment 206200 [details] [review]: ::: glib/gkeyfile.c @@ +890,2 @@ if (length == (gsize)-1) length = strlen (data); Hm, won't this segfault if length == 0 and data == NULL?
NULL is a perfectly legitimate pointer to an array of length 0. If the array has a length of zero then you are not entitled to do anything with the pointer anyway (because even reading the first element would already be past the end of the array). Consider also that g_new() returns NULL if the number of requested elements is zero...
Review of attachment 206200 [details] [review]: Nevermind, I misread the code. Looks good.
Attachment 206200 [details] pushed as 9bfde4a - GKeyFile: allow loading from empty strings