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 677817 - g_key_file_to_data adds extra blank lines in some cases
g_key_file_to_data adds extra blank lines in some cases
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.32.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-06-10 16:29 UTC by Ilya Gordeev
Modified: 2012-06-15 22:53 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Ilya Gordeev 2012-06-10 16:29:46 UTC
Here is test program:
=========
#include <glib.h>
#include <assert.h>

int main() {
	GKeyFile *kfini = g_key_file_new();

	assert(g_key_file_load_from_file(kfini, "ini_orig", G_KEY_FILE_KEEP_COMMENTS, NULL));

	g_key_file_set_integer(kfini, "Group1", "key2", 0);
	assert(g_key_file_remove_key(kfini, "Group1", "key2", NULL));

	gsize len;
	gchar *data = g_key_file_to_data(kfini, &len, NULL);
	assert(data != NULL && len != 0);
	assert(g_file_set_contents("ini_new", data, len, NULL));
	g_free(data);

	g_key_file_free(kfini);
	return 0;
}
=========
Here is test ini_orig file:
=========

[Group1]
key1=value1

[Group2]
key1=value1

=========
And after run ./test_program blank line adds at the end of [Group1]:
=========
$ diff -u ini_orig init_new
--- ini_orig
+++ ini_new
@@ -2,6 +2,7 @@
 [Group1]
 key1=value1
 
+
 [Group2]
 key1=value1
 
=========
I found this problem in these applications using GKeyFile:
mc after work ending, ini-file '.config/mc/ini', groups '[Midnight-Commander]' and '[Layout]'
evince after printing some document, ini-file '.config/evince/print-settings', group '[Print Settings]'