From 5bea9385b08d867d8bca9f9d05068c36afb985a0 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 8 Apr 2013 15:32:15 -0400 Subject: [PATCH] gitypelib: And another fix for empty strings --- gitypelib.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/gitypelib.c b/gitypelib.c index f7d07e3f8..a643cde19 100644 --- a/gitypelib.c +++ b/gitypelib.c @@ -226,6 +226,7 @@ g_typelib_get_dir_entry_by_gtype_name (GITypelib *typelib, typedef struct { const char *s; const char *separator; + gsize sep_len; GString buf; } StrSplitIter; @@ -236,6 +237,7 @@ strsplit_iter_init (StrSplitIter *iter, { iter->s = s; iter->separator = separator; + iter->sep_len = strlen (separator); iter->buf.str = NULL; iter->buf.len = 0; iter->buf.allocated_len = 0; @@ -254,7 +256,7 @@ strsplit_iter_next (StrSplitIter *iter, next = strstr (s, iter->separator); if (next) { - iter->s = next + 1; + iter->s = next + iter->sep_len; len = next - s; } else @@ -262,8 +264,15 @@ strsplit_iter_next (StrSplitIter *iter, iter->s = NULL; len = strlen (s); } - g_string_overwrite_len (&iter->buf, 0, s, (gssize)len); - *out_val = iter->buf.str; + if (len == 0) + { + *out_val = ""; + } + else + { + g_string_overwrite_len (&iter->buf, 0, s, (gssize)len); + *out_val = iter->buf.str; + } return TRUE; }