[tracker] Fixed indexer invalid writes in state_to_string() if string is empty
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker] Fixed indexer invalid writes in state_to_string() if string is empty
- Date: Wed, 6 May 2009 10:26:25 -0400 (EDT)
commit 710d3c5270334688794e040bd9396185248ac836
Author: Martyn Russell <martyn imendio com>
Date: Wed May 6 12:31:23 2009 +0100
Fixed indexer invalid writes in state_to_string() if string is empty
We assumed the string was always > 3 characters long and we always
truncated the last 3 characters which had the separator " | " appened.
---
src/tracker-indexer/tracker-indexer.c | 15 +++++++++++++--
1 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/tracker-indexer/tracker-indexer.c b/src/tracker-indexer/tracker-indexer.c
index 743b4f3..aa4850d 100644
--- a/src/tracker-indexer/tracker-indexer.c
+++ b/src/tracker-indexer/tracker-indexer.c
@@ -2006,6 +2006,7 @@ static gchar *
state_to_string (TrackerIndexerState state)
{
GString *s;
+ gchar *str, *p;
s = g_string_new ("");
@@ -2019,9 +2020,19 @@ state_to_string (TrackerIndexerState state)
s = g_string_append (s, "STOPPED | ");
}
- s->str[s->len - 3] = '\0';
+ str = g_string_free (s, FALSE);
- return g_string_free (s, FALSE);
+ /* Remove last separator */
+ p = g_utf8_strrchr (str, -1, '|');
+ if (p) {
+ /* Go back one to the space before '|' */
+ p--;
+
+ /* NULL terminate here */
+ *p = '\0';
+ }
+
+ return str;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]