parse_value() doesn't trim the string.
Lest say BlackList = coreutils, mono the parsed list looks like -> 'coreutils', ' mono'
Signed-off-by: Nikola Pajkovsky npajkovs@redhat.com --- src/cli/report.cpp | 27 ++------------------------- src/daemon/Settings.cpp | 10 ++++++++-- src/include/abrtlib.h | 2 ++ src/lib/strbuf.c | 23 +++++++++++++++++++++++ 4 files changed, 35 insertions(+), 27 deletions(-)
diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 172cb8f..e2873a2 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -23,29 +23,6 @@ #define FIELD_SEP "%----"
/* - * Trims whitespace characters both from left and right side of a string. - * Modifies the string in-place. Returns the trimmed string. - */ -static char *trim(char *str) -{ - if (!str) - return NULL; - - // Remove leading spaces. - overlapping_strcpy(str, skip_whitespace(str)); - - // Remove trailing spaces. - int i = strlen(str); - while (--i >= 0) - { - if (!isspace(str[i])) - break; - } - str[++i] = '\0'; - return str; -} - -/* * Escapes the field content string to avoid confusion with file comments. * Returned field must be free()d by caller. */ @@ -226,11 +203,11 @@ static int read_crash_report_field(const char *text, crash_data_t *report, char newvalue[length + 1]; strncpy(newvalue, textfield, length); newvalue[length] = '\0'; - trim(newvalue); + strtrim(newvalue);
char oldvalue[strlen(value->content) + 1]; strcpy(oldvalue, value->content); - trim(oldvalue); + strtrim(oldvalue);
// Return if no change in the contents detected. if (strcmp(newvalue, oldvalue) == 0) diff --git a/src/daemon/Settings.cpp b/src/daemon/Settings.cpp index e25b795..b3d1ade 100644 --- a/src/daemon/Settings.cpp +++ b/src/daemon/Settings.cpp @@ -64,11 +64,14 @@ static GList *parse_list(const char* list) struct strbuf *item = strbuf_new(); GList *l = NULL;
+ char *trim_item = NULL; + for (unsigned ii = 0; list[ii]; ii++) { if (list[ii] == ',') { - l = g_list_append(l, xstrdup(item->buf)); + trim_item = strtrim(item->buf); + l = g_list_append(l, xstrdup(trim_item)); strbuf_clear(item); } else @@ -76,7 +79,10 @@ static GList *parse_list(const char* list) }
if (item->len > 0) - l = g_list_append(l, xstrdup(item->buf)); + { + trim_item = strtrim(item->buf); + l = g_list_append(l, xstrdup(trim_item)); + }
strbuf_free(item); return l; diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index d936467..70dc300 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -94,6 +94,8 @@ extern "C" { int prefixcmp(const char *str, const char *prefix); #define suffixcmp abrt_suffixcmp int suffixcmp(const char *str, const char *suffix); +#define strtrim abrt_strtrim +char *strtrim(char *str); #define concat_path_file abrt_concat_path_file char *concat_path_file(const char *path, const char *filename); #define append_to_malloced_string abrt_append_to_malloced_string diff --git a/src/lib/strbuf.c b/src/lib/strbuf.c index f56815a..572f11c 100644 --- a/src/lib/strbuf.c +++ b/src/lib/strbuf.c @@ -37,6 +37,29 @@ int suffixcmp(const char *str, const char *suffix) return strcmp(str + len_minus_suflen, suffix); }
+/* + * Trims whitespace characters both from left and right side of a string. + * Modifies the string in-place. Returns the trimmed string. + */ +char *strtrim(char *str) +{ + if (!str) + return NULL; + + // Remove leading spaces. + overlapping_strcpy(str, skip_whitespace(str)); + + // Remove trailing spaces. + int i = strlen(str); + while (--i >= 0) + { + if (!isspace(str[i])) + break; + } + str[++i] = '\0'; + return str; +} + struct strbuf *strbuf_new(void) { struct strbuf *buf = xzalloc(sizeof(*buf));
Seems ok, please apply.
Jirka
On 04/04/2011 12:06 PM, Nikola Pajkovsky wrote:
parse_value() doesn't trim the string.
Lest say BlackList = coreutils, mono the parsed list looks like -> 'coreutils', ' mono'
Signed-off-by: Nikola Pajkovskynpajkovs@redhat.com
src/cli/report.cpp | 27 ++------------------------- src/daemon/Settings.cpp | 10 ++++++++-- src/include/abrtlib.h | 2 ++ src/lib/strbuf.c | 23 +++++++++++++++++++++++ 4 files changed, 35 insertions(+), 27 deletions(-)
diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 172cb8f..e2873a2 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -23,29 +23,6 @@ #define FIELD_SEP "%----"
/*
- Trims whitespace characters both from left and right side of a string.
- Modifies the string in-place. Returns the trimmed string.
- */
-static char *trim(char *str) -{
- if (!str)
return NULL;
- // Remove leading spaces.
- overlapping_strcpy(str, skip_whitespace(str));
- // Remove trailing spaces.
- int i = strlen(str);
- while (--i>= 0)
- {
if (!isspace(str[i]))
break;
- }
- str[++i] = '\0';
- return str;
-}
-/*
- Escapes the field content string to avoid confusion with file comments.
- Returned field must be free()d by caller.
*/ @@ -226,11 +203,11 @@ static int read_crash_report_field(const char *text, crash_data_t *report, char newvalue[length + 1]; strncpy(newvalue, textfield, length); newvalue[length] = '\0';
- trim(newvalue);
strtrim(newvalue);
char oldvalue[strlen(value->content) + 1]; strcpy(oldvalue, value->content);
- trim(oldvalue);
strtrim(oldvalue);
// Return if no change in the contents detected. if (strcmp(newvalue, oldvalue) == 0)
diff --git a/src/daemon/Settings.cpp b/src/daemon/Settings.cpp index e25b795..b3d1ade 100644 --- a/src/daemon/Settings.cpp +++ b/src/daemon/Settings.cpp @@ -64,11 +64,14 @@ static GList *parse_list(const char* list) struct strbuf *item = strbuf_new(); GList *l = NULL;
- char *trim_item = NULL;
for (unsigned ii = 0; list[ii]; ii++) { if (list[ii] == ',') {
l = g_list_append(l, xstrdup(item->buf));
trim_item = strtrim(item->buf);
l = g_list_append(l, xstrdup(trim_item)); strbuf_clear(item); } else
@@ -76,7 +79,10 @@ static GList *parse_list(const char* list) }
if (item->len> 0)
l = g_list_append(l, xstrdup(item->buf));
{
trim_item = strtrim(item->buf);
l = g_list_append(l, xstrdup(trim_item));
}
strbuf_free(item); return l;
diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index d936467..70dc300 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -94,6 +94,8 @@ extern "C" { int prefixcmp(const char *str, const char *prefix); #define suffixcmp abrt_suffixcmp int suffixcmp(const char *str, const char *suffix); +#define strtrim abrt_strtrim +char *strtrim(char *str); #define concat_path_file abrt_concat_path_file char *concat_path_file(const char *path, const char *filename); #define append_to_malloced_string abrt_append_to_malloced_string diff --git a/src/lib/strbuf.c b/src/lib/strbuf.c index f56815a..572f11c 100644 --- a/src/lib/strbuf.c +++ b/src/lib/strbuf.c @@ -37,6 +37,29 @@ int suffixcmp(const char *str, const char *suffix) return strcmp(str + len_minus_suflen, suffix); }
+/*
- Trims whitespace characters both from left and right side of a string.
- Modifies the string in-place. Returns the trimmed string.
- */
+char *strtrim(char *str) +{
- if (!str)
return NULL;
- // Remove leading spaces.
- overlapping_strcpy(str, skip_whitespace(str));
- // Remove trailing spaces.
- int i = strlen(str);
- while (--i>= 0)
- {
if (!isspace(str[i]))
break;
- }
- str[++i] = '\0';
- return str;
+}
- struct strbuf *strbuf_new(void) { struct strbuf *buf = xzalloc(sizeof(*buf));
Jiri Moskovcak jmoskovc@redhat.com writes:
Seems ok, please apply.
Jirka
merge with mainline
Thanks
On 04/04/2011 12:06 PM, Nikola Pajkovsky wrote:
parse_value() doesn't trim the string.
Lest say BlackList = coreutils, mono the parsed list looks like -> 'coreutils', ' mono'
Signed-off-by: Nikola Pajkovskynpajkovs@redhat.com
src/cli/report.cpp | 27 ++------------------------- src/daemon/Settings.cpp | 10 ++++++++-- src/include/abrtlib.h | 2 ++ src/lib/strbuf.c | 23 +++++++++++++++++++++++ 4 files changed, 35 insertions(+), 27 deletions(-)
diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 172cb8f..e2873a2 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -23,29 +23,6 @@ #define FIELD_SEP "%----"
/*
- Trims whitespace characters both from left and right side of a string.
- Modifies the string in-place. Returns the trimmed string.
- */
-static char *trim(char *str) -{
- if (!str)
return NULL;
- // Remove leading spaces.
- overlapping_strcpy(str, skip_whitespace(str));
- // Remove trailing spaces.
- int i = strlen(str);
- while (--i>= 0)
- {
if (!isspace(str[i]))
break;
- }
- str[++i] = '\0';
- return str;
-}
-/*
- Escapes the field content string to avoid confusion with file comments.
- Returned field must be free()d by caller.
*/ @@ -226,11 +203,11 @@ static int read_crash_report_field(const char *text, crash_data_t *report, char newvalue[length + 1]; strncpy(newvalue, textfield, length); newvalue[length] = '\0';
- trim(newvalue);
strtrim(newvalue);
char oldvalue[strlen(value->content) + 1]; strcpy(oldvalue, value->content);
- trim(oldvalue);
strtrim(oldvalue);
// Return if no change in the contents detected. if (strcmp(newvalue, oldvalue) == 0)
diff --git a/src/daemon/Settings.cpp b/src/daemon/Settings.cpp index e25b795..b3d1ade 100644 --- a/src/daemon/Settings.cpp +++ b/src/daemon/Settings.cpp @@ -64,11 +64,14 @@ static GList *parse_list(const char* list) struct strbuf *item = strbuf_new(); GList *l = NULL;
- char *trim_item = NULL;
for (unsigned ii = 0; list[ii]; ii++) { if (list[ii] == ',') {
l = g_list_append(l, xstrdup(item->buf));
trim_item = strtrim(item->buf);
l = g_list_append(l, xstrdup(trim_item)); strbuf_clear(item); } else
@@ -76,7 +79,10 @@ static GList *parse_list(const char* list) }
if (item->len> 0)
l = g_list_append(l, xstrdup(item->buf));
{
trim_item = strtrim(item->buf);
l = g_list_append(l, xstrdup(trim_item));
}
strbuf_free(item); return l;
diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index d936467..70dc300 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -94,6 +94,8 @@ extern "C" { int prefixcmp(const char *str, const char *prefix); #define suffixcmp abrt_suffixcmp int suffixcmp(const char *str, const char *suffix); +#define strtrim abrt_strtrim +char *strtrim(char *str); #define concat_path_file abrt_concat_path_file char *concat_path_file(const char *path, const char *filename); #define append_to_malloced_string abrt_append_to_malloced_string diff --git a/src/lib/strbuf.c b/src/lib/strbuf.c index f56815a..572f11c 100644 --- a/src/lib/strbuf.c +++ b/src/lib/strbuf.c @@ -37,6 +37,29 @@ int suffixcmp(const char *str, const char *suffix) return strcmp(str + len_minus_suflen, suffix); }
+/*
- Trims whitespace characters both from left and right side of a string.
- Modifies the string in-place. Returns the trimmed string.
- */
+char *strtrim(char *str) +{
- if (!str)
return NULL;
- // Remove leading spaces.
- overlapping_strcpy(str, skip_whitespace(str));
- // Remove trailing spaces.
- int i = strlen(str);
- while (--i>= 0)
- {
if (!isspace(str[i]))
break;
- }
- str[++i] = '\0';
- return str;
+}
- struct strbuf *strbuf_new(void) { struct strbuf *buf = xzalloc(sizeof(*buf));
crash-catcher@lists.fedorahosted.org