stream-manager: Fix svace defects (CHECK_AFTER_OVERFLOW / UNREACHABLE_CODE) 30/223630/3 accepted/tizen/unified/20200203.125727 submit/tizen/20200203.035951
authorSeungbae Shin <seungbae.shin@samsung.com>
Fri, 31 Jan 2020 09:47:09 +0000 (18:47 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Fri, 31 Jan 2020 09:54:36 +0000 (18:54 +0900)
[Version] 11.1.96
[Profile] Common
[Issue Type] Svace

Change-Id: If8546bafff603b9a4443f0452f5533627f991009

packaging/pulseaudio-modules-tizen.spec
src/stream-manager.c

index c7161cc..7d4aa32 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          11.1.95
+Version:          11.1.96
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 59e25dd..077a40c 100644 (file)
@@ -125,6 +125,16 @@ static const char* notify_command_type_str[] = {
 #define STREAM_MAP_STREAM_AVAIL_OUT_DEVICES "avail-out-devices"
 #define STREAM_MAP_STREAM_AVAIL_FRAMEWORKS "avail-frameworks"
 
+static bool is_valid_command(const char *func, notify_command_type_t command) {
+    if (command >= sizeof(notify_command_type_str) / sizeof(char *)) {
+        pa_log_error("[%s] invalid command: %d", func, command);
+        return false;
+    }
+
+    pa_log_debug("[%s] command: %s", func, notify_command_type_str[command]);
+    return true;
+}
+
 bool stream_is_call_family(pa_object *stream) {
     const char *stream_role;
     pa_proplist *prop;
@@ -1564,7 +1574,9 @@ static void fill_device_info_to_hook_data(pa_stream_manager *m, void *hook_data,
 
     pa_assert(m);
     pa_assert(hook_data);
-    pa_log_debug("command: %s", notify_command_type_str[command]);
+
+    if (!is_valid_command(__func__, command))
+        return;
 
     switch (command) {
     case NOTIFY_COMMAND_SELECT_PROPER_SINK_OR_SOURCE_FOR_INIT: {
@@ -1661,9 +1673,6 @@ static ret_msg_t prepare_and_invoke_hook_to_select_device(pa_stream_manager *m,
 
     memset(&hook_call_select_data, 0, sizeof(pa_stream_manager_hook_data_for_select));
     hook_call_select_data.stream = s = user_data;
-    if (!s)
-        return ret;
-
     hook_call_select_data.stream_type = type;
     hook_call_select_data.origins_from_new_data = is_new_data;
     if (is_new_data) {
@@ -1742,8 +1751,6 @@ static ret_msg_t prepare_and_invoke_hook_to_change_route(pa_stream_manager *m, n
         pa_assert(user_data);
         memset(&hook_call_route_data, 0, sizeof(pa_stream_manager_hook_data_for_route));
         hook_call_route_data.stream = s = user_data;
-        if (!s)
-            return ret;
 
         if (is_new_data) {
             hook_call_route_data.origins_from_new_data = true;
@@ -1808,7 +1815,9 @@ ret_msg_t do_notify(pa_stream_manager *m, notify_command_type_t command, stream_
     ret_msg_t ret = RET_MSG_OK;
 
     pa_assert(m);
-    pa_log_debug("[%s]: type(%d), is_new_data(%d), user_data(%p)", notify_command_type_str[command], type, is_new_data, user_data);
+
+    if (!is_valid_command(__func__, command))
+        return RET_MSG_ERROR_INVALID_ARGUMENT;
 
     switch (command) {
     case NOTIFY_COMMAND_SELECT_PROPER_SINK_OR_SOURCE_FOR_INIT: