Fix: common.c: logically dead code
[babeltrace.git] / src / common / common.c
index ed1d1c277f687d614d3795698e5e29044888d8b6..404357a38beed46ebf55e086c17542c14cdf3e3a 100644 (file)
@@ -49,7 +49,7 @@
 #include <sys/ioctl.h>
 #endif
 
-#define SYSTEM_PLUGIN_PATH     INSTALL_LIBDIR "/babeltrace2/plugins"
+#define SYSTEM_PLUGIN_PATH     BABELTRACE_PLUGINS_DIR
 #define HOME_ENV_VAR           "HOME"
 #define HOME_PLUGIN_SUBPATH    "/.local/lib/babeltrace2/plugins"
 
@@ -1115,9 +1115,7 @@ error:
                norm_path = NULL;
        }
 end:
-       if (tmp) {
-               free(tmp);
-       }
+       free(tmp);
        return norm_path;
 }
 #else
@@ -1782,9 +1780,7 @@ end:
                g_strfreev(lines);
        }
 
-       if (line_words) {
-               g_strfreev(line_words);
-       }
+       BT_ASSERT(!line_words);
 
        if (tmp_line) {
                g_string_free(tmp_line, TRUE);
@@ -1824,3 +1820,35 @@ end:
        return ret;
 }
 #endif /* __MINGW32__ */
+
+BT_HIDDEN
+int bt_common_g_string_append_printf(GString *str, const char *fmt, ...)
+{
+       va_list ap;
+       gsize len, allocated_len, available_len;
+       int print_len;
+
+       /* str->len excludes \0. */
+       len = str->len;
+       /* Explicitly exclude \0. */
+       allocated_len = str->allocated_len - 1;
+       available_len = allocated_len - len;
+
+       str->len = allocated_len;
+       va_start(ap, fmt);
+       print_len = vsnprintf(str->str + len, available_len + 1, fmt, ap);
+       va_end(ap);
+       if (print_len < 0) {
+               return print_len;
+       }
+       if (G_UNLIKELY(available_len < print_len)) {
+               /* Resize. */
+               g_string_set_size(str, len + print_len);
+               va_start(ap, fmt);
+               print_len = vsprintf(str->str + len, fmt, ap);
+               va_end(ap);
+       } else {
+               str->len = len + print_len;
+       }
+       return print_len;
+}
This page took 0.024715 seconds and 4 git commands to generate.