|
|
4b6aa8 |
From 99d045d33f9805d7f81012d2bf7f01edcddb97f2 Mon Sep 17 00:00:00 2001
|
|
|
4b6aa8 |
From: Ernestas Kulik <ekulik@redhat.com>
|
|
|
4b6aa8 |
Date: Tue, 4 Jun 2019 15:46:20 +0200
|
|
|
4b6aa8 |
Subject: [PATCH] lib: problem_data: Use g_strsplit()
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
Our own implementation is rather opaque and is causing Coverity to yell.
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
Signed-off-by: Ernestas Kulik <ekulik@redhat.com>
|
|
|
4b6aa8 |
---
|
|
|
4b6aa8 |
src/lib/problem_data.c | 44 ++----------------------------------------
|
|
|
4b6aa8 |
1 file changed, 2 insertions(+), 42 deletions(-)
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
diff --git a/src/lib/problem_data.c b/src/lib/problem_data.c
|
|
|
4b6aa8 |
index 2f66fb3..fdecc83 100644
|
|
|
4b6aa8 |
--- a/src/lib/problem_data.c
|
|
|
4b6aa8 |
+++ b/src/lib/problem_data.c
|
|
|
4b6aa8 |
@@ -519,56 +519,16 @@ problem_data_t *create_problem_data_from_dump_dir(struct dump_dir *dd)
|
|
|
4b6aa8 |
return problem_data;
|
|
|
4b6aa8 |
}
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
-/*
|
|
|
4b6aa8 |
- * Returns NULL-terminated char *vector[]. Result itself must be freed,
|
|
|
4b6aa8 |
- * but do no free list elements. IOW: do free(result), but never free(result[i])!
|
|
|
4b6aa8 |
- * If comma_separated_list is NULL or "", returns NULL.
|
|
|
4b6aa8 |
- */
|
|
|
4b6aa8 |
-static char **build_exclude_vector(const char *comma_separated_list)
|
|
|
4b6aa8 |
-{
|
|
|
4b6aa8 |
- char **exclude_items = NULL;
|
|
|
4b6aa8 |
- if (comma_separated_list && comma_separated_list[0])
|
|
|
4b6aa8 |
- {
|
|
|
4b6aa8 |
- /* even w/o commas, we'll need two elements:
|
|
|
4b6aa8 |
- * exclude_items[0] = "name"
|
|
|
4b6aa8 |
- * exclude_items[1] = NULL
|
|
|
4b6aa8 |
- */
|
|
|
4b6aa8 |
- unsigned cnt = 2;
|
|
|
4b6aa8 |
-
|
|
|
4b6aa8 |
- const char *cp = comma_separated_list;
|
|
|
4b6aa8 |
- while (*cp)
|
|
|
4b6aa8 |
- if (*cp++ == ',')
|
|
|
4b6aa8 |
- cnt++;
|
|
|
4b6aa8 |
-
|
|
|
4b6aa8 |
- /* We place the string directly after the char *vector[cnt]: */
|
|
|
4b6aa8 |
- exclude_items = xzalloc(cnt * sizeof(exclude_items[0]) + (cp - comma_separated_list) + 1);
|
|
|
4b6aa8 |
- char *p = strcpy((char*)&exclude_items[cnt], comma_separated_list);
|
|
|
4b6aa8 |
-
|
|
|
4b6aa8 |
- char **pp = exclude_items;
|
|
|
4b6aa8 |
- *pp++ = p;
|
|
|
4b6aa8 |
- while (*p)
|
|
|
4b6aa8 |
- {
|
|
|
4b6aa8 |
- if (*p++ == ',')
|
|
|
4b6aa8 |
- {
|
|
|
4b6aa8 |
- p[-1] = '\0';
|
|
|
4b6aa8 |
- *pp++ = p;
|
|
|
4b6aa8 |
- }
|
|
|
4b6aa8 |
- }
|
|
|
4b6aa8 |
- }
|
|
|
4b6aa8 |
-
|
|
|
4b6aa8 |
- return exclude_items;
|
|
|
4b6aa8 |
-}
|
|
|
4b6aa8 |
-
|
|
|
4b6aa8 |
problem_data_t *create_problem_data_for_reporting(const char *dump_dir_name)
|
|
|
4b6aa8 |
{
|
|
|
4b6aa8 |
struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
|
|
|
4b6aa8 |
if (!dd)
|
|
|
4b6aa8 |
return NULL; /* dd_opendir already emitted error msg */
|
|
|
4b6aa8 |
- char **exclude_items = build_exclude_vector(getenv("EXCLUDE_FROM_REPORT"));
|
|
|
4b6aa8 |
+ char **exclude_items = g_strsplit(getenv("EXCLUDE_FROM_REPORT"), ",", -1);
|
|
|
4b6aa8 |
problem_data_t *problem_data = problem_data_new();
|
|
|
4b6aa8 |
problem_data_load_from_dump_dir(problem_data, dd, exclude_items);
|
|
|
4b6aa8 |
dd_close(dd);
|
|
|
4b6aa8 |
- free(exclude_items);
|
|
|
4b6aa8 |
+ g_strfreev(exclude_items);
|
|
|
4b6aa8 |
return problem_data;
|
|
|
4b6aa8 |
}
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
--
|
|
|
4b6aa8 |
2.21.0
|
|
|
4b6aa8 |
|