SF.net SVN: geany:[5721] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Wed Apr 13 12:59:20 UTC 2011


Revision: 5721
          http://geany.svn.sourceforge.net/geany/?rev=5721&view=rev
Author:   ntrel
Date:     2011-04-13 12:59:20 +0000 (Wed, 13 Apr 2011)

Log Message:
-----------
Make utils_build_path() return a copy for safety.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/editor.c
    trunk/src/filetypes.c
    trunk/src/keyfile.c
    trunk/src/symbols.c
    trunk/src/templates.c
    trunk/src/toolbar.c
    trunk/src/utils.c
    trunk/src/utils.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2011-04-13 12:22:30 UTC (rev 5720)
+++ trunk/ChangeLog	2011-04-13 12:59:20 UTC (rev 5721)
@@ -5,6 +5,9 @@
    about parameter addresses.
  * src/document.h:
    Use brackets for DOC_FILENAME() macro 'doc' argument.
+ * src/templates.c, src/utils.c, src/toolbar.c, src/utils.h,
+   src/keyfile.c, src/filetypes.c, src/editor.c, src/symbols.c:
+   Make utils_build_path() return a copy for safety.
 
 
 2011-04-12  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>

Modified: trunk/src/editor.c
===================================================================
--- trunk/src/editor.c	2011-04-13 12:22:30 UTC (rev 5720)
+++ trunk/src/editor.c	2011-04-13 12:59:20 UTC (rev 5721)
@@ -4814,15 +4814,17 @@
 
 static void on_document_save(GObject *obj, GeanyDocument *doc)
 {
+	gchar *f = utils_build_path(app->configdir, "snippets.conf", NULL);
+
 	g_return_if_fail(NZV(doc->real_path));
 
-	if (utils_str_equal(doc->real_path,
-		utils_build_path(app->configdir, "snippets.conf", NULL)))
+	if (utils_str_equal(doc->real_path, f))
 	{
 		/* reload snippets */
 		editor_snippets_free();
 		editor_snippets_init();
 	}
+	g_free(f);
 }
 
 
@@ -4849,6 +4851,7 @@
 void editor_init(void)
 {
 	static GeanyIndentPrefs indent_prefs;
+	gchar *f;
 
 	memset(&editor_prefs, 0, sizeof(GeanyEditorPrefs));
 	memset(&indent_prefs, 0, sizeof(GeanyIndentPrefs));
@@ -4858,8 +4861,9 @@
 	 * handler (on_editor_notify) is called */
 	g_signal_connect_after(geany_object, "editor-notify", G_CALLBACK(on_editor_notify), NULL);
 
-	ui_add_config_file_menu_item(utils_build_path(app->configdir, "snippets.conf", NULL),
-		NULL, NULL);
+	f = utils_build_path(app->configdir, "snippets.conf", NULL);
+	ui_add_config_file_menu_item(f, NULL, NULL);
+	g_free(f);
 	g_signal_connect(geany_object, "document-save", G_CALLBACK(on_document_save), NULL);
 }
 

Modified: trunk/src/filetypes.c
===================================================================
--- trunk/src/filetypes.c	2011-04-13 12:22:30 UTC (rev 5720)
+++ trunk/src/filetypes.c	2011-04-13 12:59:20 UTC (rev 5721)
@@ -609,6 +609,7 @@
 void filetypes_init_types()
 {
 	filetype_id ft_id;
+	gchar *f;
 
 	g_return_if_fail(filetypes_array == NULL);
 	g_return_if_fail(filetypes_hash == NULL);
@@ -629,7 +630,9 @@
 		filetype_add(filetypes[ft_id]);
 	}
 	init_custom_filetypes(app->datadir);
-	init_custom_filetypes(utils_build_path(app->configdir, GEANY_FILEDEFS_SUBDIR, NULL));
+	f = utils_build_path(app->configdir, GEANY_FILEDEFS_SUBDIR, NULL);
+	init_custom_filetypes(f);
+	g_free(f);
 
 	/* sort last instead of on insertion to prevent exponential time */
 	filetypes_by_title = g_slist_sort_with_data(filetypes_by_title,
@@ -639,13 +642,17 @@
 
 static void on_document_save(G_GNUC_UNUSED GObject *object, GeanyDocument *doc)
 {
+	gchar *f;
+
 	g_return_if_fail(NZV(doc->real_path));
 
-	if (utils_str_equal(doc->real_path,
-		utils_build_path(app->configdir, "filetype_extensions.conf", NULL)))
+	f = utils_build_path(app->configdir, "filetype_extensions.conf", NULL);
+	if (utils_str_equal(doc->real_path, f))
 		filetypes_read_extensions();
-	else if (utils_str_equal(doc->real_path,
-		utils_build_path(app->configdir, GEANY_FILEDEFS_SUBDIR, "filetypes.common", NULL)))
+
+	g_free(f);
+	f = utils_build_path(app->configdir, GEANY_FILEDEFS_SUBDIR, "filetypes.common", NULL);
+	if (utils_str_equal(doc->real_path, f))
 	{
 		guint i;
 
@@ -656,16 +663,20 @@
 		foreach_document(i)
 			document_reload_config(documents[i]);
 	}
+	g_free(f);
 }
 
 
 static void setup_config_file_menus(void)
 {
-	ui_add_config_file_menu_item(
-		utils_build_path(app->configdir, "filetype_extensions.conf", NULL), NULL, NULL);
-	ui_add_config_file_menu_item(
-		utils_build_path(app->configdir, GEANY_FILEDEFS_SUBDIR, "filetypes.common", NULL), NULL, NULL);
+	gchar *f;
 
+	f = utils_build_path(app->configdir, "filetype_extensions.conf", NULL);
+	ui_add_config_file_menu_item(f, NULL, NULL);
+	setptr(f, utils_build_path(app->configdir, GEANY_FILEDEFS_SUBDIR, "filetypes.common", NULL));
+	ui_add_config_file_menu_item(f, NULL, NULL);
+	g_free(f);
+
 	g_signal_connect(geany_object, "document-save", G_CALLBACK(on_document_save), NULL);
 }
 
@@ -770,7 +781,7 @@
 static GeanyFiletype *check_builtin_filenames(const gchar *utf8_filename)
 {
 	gchar *lfn = NULL;
-	const gchar *path;
+	gchar *path;
 	gboolean found = FALSE;
 
 #ifdef G_OS_WIN32
@@ -785,10 +796,11 @@
 	if (g_str_has_prefix(lfn, path))
 		found = TRUE;
 
-	path = utils_build_path(app->datadir, "filetypes.", NULL);
+	setptr(path, utils_build_path(app->datadir, "filetypes.", NULL));
 	if (g_str_has_prefix(lfn, path))
 		found = TRUE;
 
+	g_free(path);
 	g_free(lfn);
 	return found ? filetypes[GEANY_FILETYPES_CONF] : NULL;
 }

Modified: trunk/src/keyfile.c
===================================================================
--- trunk/src/keyfile.c	2011-04-13 12:22:30 UTC (rev 5720)
+++ trunk/src/keyfile.c	2011-04-13 12:59:20 UTC (rev 5721)
@@ -962,16 +962,17 @@
 
 gboolean configuration_load(void)
 {
-	const gchar *configfile = utils_build_path(app->configdir, "geany.conf", NULL);
+	gchar *configfile = utils_build_path(app->configdir, "geany.conf", NULL);
 	GKeyFile *config = g_key_file_new();
 
 	if (! g_file_test(configfile, G_FILE_TEST_IS_REGULAR))
 	{	/* config file does not (yet) exist, so try to load a global config file which may be */
 		/* created by distributors */
 		geany_debug("No user config file found, trying to use global configuration.");
-		configfile = utils_build_path(app->datadir, "geany.conf", NULL);
+		setptr(configfile, utils_build_path(app->datadir, "geany.conf", NULL));
 	}
 	g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL);
+	g_free(configfile);
 
 	load_dialog_prefs(config);
 	load_ui_prefs(config);

Modified: trunk/src/symbols.c
===================================================================
--- trunk/src/symbols.c	2011-04-13 12:22:30 UTC (rev 5720)
+++ trunk/src/symbols.c	2011-04-13 12:59:20 UTC (rev 5721)
@@ -1729,7 +1729,7 @@
 {
 	GSList *file_list = NULL, *list = NULL;
 	GHashTable *lang_hash;
-	const gchar *dir;
+	gchar *dir;
 
 	dir = utils_build_path(app->configdir, "tags", NULL);
 	/* create the user tags dir for next time if it doesn't exist */
@@ -1739,8 +1739,10 @@
 	}
 	file_list = utils_get_file_list_full(dir, TRUE, TRUE, NULL);
 
-	dir = utils_build_path(app->datadir, "tags", NULL);
-	list =  utils_get_file_list_full(dir, TRUE, TRUE, NULL);
+	setptr(dir, utils_build_path(app->datadir, "tags", NULL));
+	list = utils_get_file_list_full(dir, TRUE, TRUE, NULL);
+	g_free(dir);
+
 	file_list = g_slist_concat(file_list, list);
 
 	lang_hash = get_tagfile_hash(file_list);
@@ -2168,20 +2170,27 @@
 
 static void on_document_save(G_GNUC_UNUSED GObject *object, GeanyDocument *doc)
 {
+	gchar *f = utils_build_path(app->configdir, "ignore.tags", NULL);
+
 	g_return_if_fail(NZV(doc->real_path));
 
-	if (utils_str_equal(doc->real_path,
-		utils_build_path(app->configdir, "ignore.tags", NULL)))
+	if (utils_str_equal(doc->real_path, f))
 		load_c_ignore_tags();
+
+	g_free(f);
 }
 
 
 void symbols_init(void)
 {
+	gchar *f;
+
 	create_taglist_popup_menu();
 
-	ui_add_config_file_menu_item(utils_build_path(app->configdir, "ignore.tags", NULL),
-		NULL, NULL);
+	f = utils_build_path(app->configdir, "ignore.tags", NULL);
+	ui_add_config_file_menu_item(f, NULL, NULL);
+	g_free(f);
+
 	g_signal_connect(geany_object, "document-save", G_CALLBACK(on_document_save), NULL);
 }
 

Modified: trunk/src/templates.c
===================================================================
--- trunk/src/templates.c	2011-04-13 12:22:30 UTC (rev 5720)
+++ trunk/src/templates.c	2011-04-13 12:59:20 UTC (rev 5721)
@@ -327,7 +327,7 @@
 /* reload templates if any file in the templates path is saved */
 static void on_document_save(G_GNUC_UNUSED GObject *object, GeanyDocument *doc)
 {
-	const gchar *path = utils_build_path(app->configdir, GEANY_TEMPLATES_SUBDIR, NULL);
+	gchar *path = utils_build_path(app->configdir, GEANY_TEMPLATES_SUBDIR, NULL);
 
 	g_return_if_fail(NZV(doc->real_path));
 
@@ -337,6 +337,7 @@
 		templates_free_templates();
 		templates_init();
 	}
+	g_free(path);
 }
 
 

Modified: trunk/src/toolbar.c
===================================================================
--- trunk/src/toolbar.c	2011-04-13 12:22:30 UTC (rev 5720)
+++ trunk/src/toolbar.c	2011-04-13 12:59:20 UTC (rev 5721)
@@ -177,7 +177,7 @@
 	GSList *l;
 	GtkWidget *entry;
 	GError *error = NULL;
-	const gchar *filename;
+	gchar *filename;
 	static guint merge_id = 0;
 	GtkWidget *toolbar_new_file_menu = NULL;
 	GtkWidget *toolbar_recent_files_menu = NULL;
@@ -226,9 +226,10 @@
 			g_error_free(error);
 			error = NULL;
 
-			filename = utils_build_path(app->datadir, "ui_toolbar.xml", NULL);
+			setptr(filename, utils_build_path(app->datadir, "ui_toolbar.xml", NULL));
 			merge_id = gtk_ui_manager_add_ui_from_file(uim, filename, &error);
 		}
+		g_free(filename);
 	}
 	if (error != NULL)
 	{
@@ -890,7 +891,7 @@
 A list of available actions can be found in the documentation included with Geany or\n\
 at http://www.geany.org/manual/current/index.html#customizing-the-toolbar.\n-->\n\
 \t<toolbar name='GeanyToolbar'>\n";
-	const gchar *filename = utils_build_path(app->configdir, "ui_toolbar.xml", NULL);
+	gchar *filename;
 	GString *str = g_string_new(template);
 
 	gtk_tree_model_foreach(GTK_TREE_MODEL(tbw->store_used), tb_editor_foreach_used, str);
@@ -899,7 +900,9 @@
 
 	toolbar_reload(str->str);
 
+	filename = utils_build_path(app->configdir, "ui_toolbar.xml", NULL);
 	utils_write_file(filename, str->str);
+	g_free(filename);
 
 	g_string_free(str, TRUE);
 }

Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c	2011-04-13 12:22:30 UTC (rev 5720)
+++ trunk/src/utils.c	2011-04-13 12:59:20 UTC (rev 5721)
@@ -1741,12 +1741,8 @@
 }
 
 
-/* Similar to g_build_path() but (re)using a fixed buffer, so never free it.
- * This assumes a small enough resulting string length to be kept without freeing,
- * but this should be the case for filenames.
- * @warning As the buffer is reused, you can't call this recursively, e.g. for a
- * function argument and within the function called. */
-const gchar *utils_build_path(const gchar *first, ...)
+/* Like g_build_path() but without first argument. */
+gchar *utils_build_path(const gchar *first, ...)
 {
 	static GString *buffer = NULL;
 	va_list args;
@@ -1761,7 +1757,7 @@
 	va_start(args, first);
 	utils_string_vappend(buffer, G_DIR_SEPARATOR_S, args);
 	va_end(args);
-	return buffer->str;
+	return g_strdup(buffer->str);
 }
 
 

Modified: trunk/src/utils.h
===================================================================
--- trunk/src/utils.h	2011-04-13 12:22:30 UTC (rev 5720)
+++ trunk/src/utils.h	2011-04-13 12:59:20 UTC (rev 5721)
@@ -247,7 +247,7 @@
 
 gint utils_str_casecmp(const gchar *s1, const gchar *s2);
 
-const gchar *utils_build_path(const gchar *first, ...) G_GNUC_NULL_TERMINATED;
+gchar *utils_build_path(const gchar *first, ...) G_GNUC_NULL_TERMINATED;
 
 gchar *utils_make_filename(const gchar *path, ...) G_GNUC_NULL_TERMINATED;
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list