[gnome-builder/wip/parsing] auto-indent: handle parse failures a bit more gracefully.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/parsing] auto-indent: handle parse failures a bit more gracefully.
- Date: Sat, 20 Sep 2014 21:06:12 +0000 (UTC)
commit 1d6e589761c029a623c06cd941378d9fc9da1f29
Author: Christian Hergert <christian hergert me>
Date: Sat Sep 20 14:06:00 2014 -0700
auto-indent: handle parse failures a bit more gracefully.
src/editor/c-parse-helper.c | 29 +++++++++++++++++------------
tests/test-c-parse-helper.c | 10 ++++++++++
2 files changed, 27 insertions(+), 12 deletions(-)
---
diff --git a/src/editor/c-parse-helper.c b/src/editor/c-parse-helper.c
index d73d339..29b189e 100644
--- a/src/editor/c-parse-helper.c
+++ b/src/editor/c-parse-helper.c
@@ -166,26 +166,31 @@ parse_parameters (const gchar *text)
const gchar *name_sep;
Parameter param = { 0 };
gboolean success = FALSE;
- gchar *reversed;
- gchar *name_rev;
+ gchar *reversed = NULL;
+ gchar *name_rev = NULL;
reversed = g_utf8_strreverse (word, -1);
name_sep = strpbrk (reversed, "\t\n *");
- name_rev = g_strndup (reversed, name_sep - reversed);
- param.name = g_strstrip (g_utf8_strreverse (name_rev, -1));
- param.type = g_strstrip (g_utf8_strreverse (name_sep, -1));
-
- if (parameter_validate (¶m))
+ if (name_sep && *name_sep && *(name_sep + 1))
{
- ret = g_slist_append (ret, parameter_copy (¶m));
- success = TRUE;
+ name_rev = g_strndup (reversed, name_sep - reversed);
+
+ param.name = g_strstrip (g_utf8_strreverse (name_rev, -1));
+ param.type = g_strstrip (g_utf8_strreverse (name_sep, -1));
+
+ if (parameter_validate (¶m))
+ {
+ ret = g_slist_append (ret, parameter_copy (¶m));
+ success = TRUE;
+ }
+
+ g_free (param.name);
+ g_free (param.type);
+ g_free (name_rev);
}
g_free (reversed);
- g_free (name_rev);
- g_free (param.name);
- g_free (param.type);
if (success)
continue;
diff --git a/tests/test-c-parse-helper.c b/tests/test-c-parse-helper.c
index 20d2ce1..48f7f31 100644
--- a/tests/test-c-parse-helper.c
+++ b/tests/test-c-parse-helper.c
@@ -60,11 +60,21 @@ test_parse_parameters1 (void)
g_slist_free (ret);
}
+static void
+test_parse_parameters2 (void)
+{
+ GSList *ret;
+
+ ret = parse_parameters ("abc, def, ghi");
+ g_assert (!ret);
+}
+
int
main (int argc,
char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/Parser/C/parse_parameters1", test_parse_parameters1);
+ g_test_add_func ("/Parser/C/parse_parameters2", test_parse_parameters2);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]