[monkey-bubble: 18/753] Fix the bug in the chomp routine



commit 56d59a51d1201f97b7828792b5f76fea42870bed
Author: Arturo Espinosa <unammx src gnome org>
Date:   Tue Dec 23 06:01:43 1997 +0000

    Fix the bug in the chomp routine

 libgnome/gnome-history.c |    3 ++-
 libgnome/gnome-string.c  |   14 ++++++++++----
 2 files changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/libgnome/gnome-history.c b/libgnome/gnome-history.c
index d5c22c5..6f861f4 100644
--- a/libgnome/gnome-history.c
+++ b/libgnome/gnome-history.c
@@ -65,7 +65,8 @@ write_history_entry(GnomeHistoryEntry ent, FILE *outfile)
 		ent->filename, ent->filetype, ent->creator, ent->desc);
 }
 
-static void write_history(GList *ents)
+static void
+write_history(GList *ents)
 {
 	FILE *outfile;
 	gchar *filename = gnome_util_home_file("document_history");
diff --git a/libgnome/gnome-string.c b/libgnome/gnome-string.c
index 9467c81..5f56f93 100644
--- a/libgnome/gnome-string.c
+++ b/libgnome/gnome-string.c
@@ -91,12 +91,11 @@ gnome_join_vstrings(gchar *separator, gchar **strings)
 	return retval;
 }
 
-inline
 gchar *
 gnome_chomp_string(gchar *astring, gboolean in_place)
 {
 	int i;
-	gchar *retval;
+	gchar *retval, *end;
 
 	g_return_val_if_fail(astring != NULL, NULL);
 
@@ -105,6 +104,13 @@ gnome_chomp_string(gchar *astring, gboolean in_place)
 	else
 		retval = astring;
 
-	i = strlen(retval) - 1;
-	while(isspace(retval[i])) retval[i--] = '\0';
+	i = strlen (retval);
+	if (!i)
+		return retval;
+
+	*end = retval + i - 1;
+ 	for (; end >= retval && isspace (*end); end--)
+		*end = '\0';
+
+	return retval;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]