Fix svace issues 52/212252/3 accepted/tizen/unified/20190821.064629 submit/tizen/20190821.011758
authorYunmi Ha <yunmi.ha@samsung.com>
Mon, 19 Aug 2019 09:20:40 +0000 (18:20 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Tue, 20 Aug 2019 05:35:07 +0000 (14:35 +0900)
Change-Id: I15a9c64c01f34c58e1506eb15786fce544b24663
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/action/unit_start.c
src/decision_makers/unit_control_dm.c
src/libactd/unit_control.c
src/listeners/dbus.c
src/listeners/unit_control_api.c

index 8db5ebd0b4053cc577dfb005d8784d9925c958d6..7e322533789a25a6db60330281a7eeb8e9bc8955 100644 (file)
@@ -63,15 +63,12 @@ static void on_job_removed(GDBusConnection *connection,
        char *job;
        int ret;
 
-       if (!data)
-               return -EINVAL;
+       assert(data);
 
        g_variant_get(parameters, "(uoss)", NULL, &job, NULL, NULL);
 
        if (strcmp(data->job, job) == 0)
                 finish_action(data, 0, NULL);
-
-       return 0;
 }
 
 
index 67e1a554d8891ac8ad32c10c55d947b620db1e87..8ed0833981aa51d6395f65e0cfdeff9954c2f1f7 100644 (file)
@@ -62,9 +62,6 @@ static int list_unit_by_pattern(const char *pattern, GVariant **reply)
        assert(pattern);
 
        GVariant *result;
-       int ret;
-       char *prefix = NULL;
-       char *joined = NULL;
        char *patterns[2] = {};
        char *unit_states[] = {
                "loaded",
@@ -79,27 +76,21 @@ static int list_unit_by_pattern(const char *pattern, GVariant **reply)
                        "ListUnitsByPatterns",
                        g_variant_new("(asas)", (char **)unit_states, (char **)patterns));
 
-       if (ret < 0) {
-               log_error_errno(ret, "failed to issue ListUnitsByPatterns() call - %m");
-               return ret;
+       if (!result) {
+               log_error("Failed to issue ListUnitsByPatterns() call.");
+               return -1;
        }
 
        *reply = result;
 
        return 0;
-
-cleanup:
-       free(prefix);
-       free(joined);
-       return ret;
 }
 
-static int parse_unit_info(GVariant *m, char **name)
+static void parse_unit_info(GVariant *m, char **name)
 {
        assert(m);
 
        char *id;
-       int ret;
 
        g_variant_get(
                m,
@@ -117,7 +108,6 @@ static int parse_unit_info(GVariant *m, char **name)
                );
 
        *name = id;
-       return ret;
 }
 
 static int parse_unit_list(GVariant *reply, struct list_head *units)
@@ -125,7 +115,6 @@ static int parse_unit_list(GVariant *reply, struct list_head *units)
        assert(reply);
        assert(units);
 
-       int ret = 0;
        char *name;
        struct unit_info *u;
        GVariantIter iter;
@@ -143,18 +132,15 @@ static int parse_unit_list(GVariant *reply, struct list_head *units)
                }
 
                u->unit = strdup(name);
-               if (!u->unit)
+               if (!u->unit) {
+                       free(u);
                        return -ENOMEM;
+               }
 
                list_add_tail(&u->node, units);
        }
 
-       if (ret < 0) {
-               log_error_errno(ret, "error parsing unit info - %m");
-               return ret;
-       }
-
-       return ret;
+       return 0;
 }
 
 static void unit_control_executed(struct decision_made_event *dm_ev, int result)
@@ -336,6 +322,8 @@ static char *construct_proper_service_name(char *requested_name, char *whitelist
        assert(whitelist_name);
 
        char *name, *ret, *at;
+       int buf_size;
+
        if (strlen(requested_name) > strlen(whitelist_name))
                name = requested_name;
        else
@@ -346,11 +334,12 @@ static char *construct_proper_service_name(char *requested_name, char *whitelist
        /* add '*' if wildcard */
        if (at) {
                at++; /* move the pointer after '@' */
-               ret = calloc(1, strlen(name)+ 2); /* one for \0 and one for additional asterisk*/
+               buf_size = strlen(name) + 2;
+               ret = calloc(1, buf_size); /* one for \0 and one for additional asterisk*/
                if (!ret)
                        return NULL;
                strncpy(ret, name, at - name);
-               sprintf(ret + (at - name), "*%s", at);
+               snprintf(ret + (at - name), buf_size-(at - name), "*%s", at);
        } else {
                ret = strdup(name);
        }
index 99c579d393add6982a064163919e2c8c2310acba..24370b65352559f28989a53d452f3413bf2a2659 100644 (file)
@@ -53,7 +53,7 @@ static void generic_callback(GObject *source_object, GAsyncResult *res, gpointer
        struct generic_user_data *data = user_data;
        GVariant *var;
        GError *err = NULL;
-       int status;
+       int status = UNIT_CONTROL_ERROR;
        const char *result;
 
        if (!data)
index 19978dad2d5f848021a02b4ed9dbb689b926b84c..435d8e4b500d594509061a3433c42c70ba24fb8d 100644 (file)
@@ -151,7 +151,7 @@ static void on_dbus_signal_match(GDBusConnection *connection,
 
        if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
                log_error_errno(errno, "Unable to get timestamp : %m");
-               return -1;
+               return ;
        }
 
        ds_ev_data.event_time = ts.tv_sec;
@@ -193,7 +193,9 @@ static void on_dbus_signal_match(GDBusConnection *connection,
        epc_event_unref(ev);
        if (ret)
                log_error_errno(ret, "Unable to report event: %m");
-       return 0;
+
+       return ;
+
 finish:
        free(ds_ev_data.event_id);
        free(ds_ev_data.sender);
@@ -204,8 +206,6 @@ finish:
        free(ds_ev_data.destination);
        if (ds_ev_data.params)
                epc_object_destroy(ds_ev_data.params);
-
-       return -1;
 }
 
 static void signal_cleanup(struct dbus_signal *s)
index 79faad63dcbac02a3ac44968fb7341e81a1b512c..02b29649d0962239741e7be1a81ff29fffd39fca 100644 (file)
@@ -161,7 +161,7 @@ static int unit_control_api_init(struct epc_module *module,
        int ret = 0;
 
        listener->bus = dbus_handle_get_connection(G_BUS_TYPE_SYSTEM, 0);
-       if (!listener->bus < 0) {
+       if (!listener->bus) {
                log_error_errno(ret, "Failed to acquire the default system bus connection: %m");
                return -EINVAL;
        }