changeset 260:249a9a6cd27f

Improve remove_trailing_slash() so it allocates no more than needed bytes and remove all trailing slashes instead only one.
author zas_
date Sat, 05 Apr 2008 15:23:39 +0000
parents fa7d69e7d02d
children 68b4c8d2653e
files src/ui_tabcomp.c
diffstat 1 files changed, 4 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/ui_tabcomp.c	Sat Apr 05 11:59:29 2008 +0000
+++ b/src/ui_tabcomp.c	Sat Apr 05 15:23:39 2008 +0000
@@ -814,15 +814,14 @@
 
 gchar *remove_trailing_slash(const gchar *path)
 {
-	gchar *ret;
 	gint l;
+
 	if (!path) return NULL;
 
-	ret = g_strdup(path);
-	l = strlen(ret);
-	if (l > 1 && ret[l - 1] == '/') ret[l - 1] = '\0';
+	l = strlen(path);
+	while (l > 1 && path[l - 1] == '/') l--;
 
-	return ret;
+	return g_strndup(path, l);
 }
 
 static void tab_completion_select_cancel_cb(FileDialog *fd, gpointer data)