summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorportix <portix@gmx.net>2011-10-19 10:41:23 +0200
committerportix <portix@gmx.net>2011-10-19 10:41:23 +0200
commit37324f34c6ff94eee764fc9ecb42175dbe73f90c (patch)
tree008d4477f8fcd7d1c5b2be4747026c1b3feaa2d2 /src/util.c
parente5f42b0aba39c3c0776b67eb6da2fe82aafbba96 (diff)
downloaddwb-37324f34c6ff94eee764fc9ecb42175dbe73f90c.zip
Fixing serveral bugs reported by clang-analyser
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/util.c b/src/util.c
index db645fe1..2814e92e 100644
--- a/src/util.c
+++ b/src/util.c
@@ -528,7 +528,7 @@ util_domain_from_uri(const char *uri) {
strncpy(domain, uri_p, p - uri_p);
}
char *ret = domain[0] ? domain : uri_p;
- return ret;
+ return g_strdup(ret);
}/*}}}*/
/* util_compare_path(char *uri) return: char* {{{*/
@@ -568,7 +568,7 @@ util_file_add(const char *filename, const char *text, int append, int max) {
if (!append)
g_string_append_printf(content, "%s\n", text);
- gboolean ret;
+ gboolean ret = true;
if ( (file = fopen(filename, "r")) ) {
for (int i=0; fgets(buffer, sizeof buffer, file) && (max < 0 || i < max-1); i++ ) {
if (STRCMP_FIRST_WORD(text, buffer) && STRCMP_SKIP_NEWLINE(text, buffer) ) {
@@ -580,10 +580,13 @@ util_file_add(const char *filename, const char *text, int append, int max) {
else {
fprintf(stderr, "Cannot open file %s\n", filename);
ret = false;
+ goto error_out;
}
if (append)
g_string_append_printf(content, "%s\n", text);
ret = util_set_file_content(filename, content->str);
+
+error_out:
g_string_free(content, true);
return ret;
}