From 4e282e9724a9e709eb439e28794c7832fa8ccf89 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Tue, 26 Mar 2019 13:31:32 +0900 Subject: [PATCH] Fix defects detected by static analysis tool Change-Id: Iafe4bb82acda7aebaf52c91b9bc52efbbcd7ee33 --- plugins/wakeup-manager/src/wakeup_manager.cpp | 83 +++++++++++-------- src/multi_assistant_service.c | 4 +- 2 files changed, 51 insertions(+), 36 deletions(-) diff --git a/plugins/wakeup-manager/src/wakeup_manager.cpp b/plugins/wakeup-manager/src/wakeup_manager.cpp index e37305d..6758c46 100644 --- a/plugins/wakeup-manager/src/wakeup_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager.cpp @@ -79,6 +79,7 @@ typedef struct { bool audio_data_require_status{false}; char engine_name[_POSIX_PATH_MAX]; char engine_path[_POSIX_PATH_MAX]; + void *engine_handle{nullptr}; wakeup_engine_interface interface{nullptr, }; std::vector assistant_list; } wakeup_engine_info; @@ -213,8 +214,7 @@ static void wakeup_engine_wakeup_event_cb(wakeup_event_info info, void* user_dat if (NULL == user_data) return; for (int loop = 0;loop < g_engine_count;loop++) { - if (NULL != g_wakeup_engine_info[loop].engine_name && - strncmp(g_wakeup_engine_info[loop].engine_name, + if (strncmp(g_wakeup_engine_info[loop].engine_name, (const char*)user_data, _POSIX_PATH_MAX) == 0) { if (g_wakeup_policy) { g_wakeup_policy->wakeup_candidate(info); @@ -230,8 +230,7 @@ static void wakeup_engine_speech_status_cb(wakeup_service_speech_status_e status if (NULL == user_data) return; for (int loop = 0;loop < g_engine_count;loop++) { - if (NULL != g_wakeup_engine_info[loop].engine_name && - strncmp(g_wakeup_engine_info[loop].engine_name, + if (strncmp(g_wakeup_engine_info[loop].engine_name, (const char*)user_data, _POSIX_PATH_MAX) == 0) { } } @@ -243,8 +242,7 @@ static void wakeup_engine_error_cb(int error, const char* err_msg, void* user_da if (NULL == user_data) return; for (int loop = 0;loop < g_engine_count;loop++) { - if (NULL != g_wakeup_engine_info[loop].engine_name && - strncmp(g_wakeup_engine_info[loop].engine_name, + if (strncmp(g_wakeup_engine_info[loop].engine_name, (const char*)user_data, _POSIX_PATH_MAX) == 0) { } } @@ -259,8 +257,7 @@ static void wakeup_engine_audio_data_require_status_cb(bool require, void* user_ // LOCK REQUIRED int audio_data_require_count = 0; for (int loop = 0;loop < g_engine_count;loop++) { - if (NULL != g_wakeup_engine_info[loop].engine_name && - strncmp(g_wakeup_engine_info[loop].engine_name, + if (strncmp(g_wakeup_engine_info[loop].engine_name, (const char*)user_data, _POSIX_PATH_MAX) == 0) { g_wakeup_engine_info[loop].audio_data_require_status = require; } @@ -288,74 +285,76 @@ static void wakeup_engine_audio_data_require_status_cb(bool require, void* user_ static void wakeup_engine_add_library(const char* name, const char* path) { - if (g_engine_count >= MAX_WAKEUP_ENGINE_NUM) return; + int index = g_engine_count; + if (index >= MAX_WAKEUP_ENGINE_NUM || index < 0) return; if (nullptr == name || nullptr == path) return; MWR_LOGD("Name (%s), Filepath(%s)", name, path); - int index = g_engine_count; char* error = NULL; - void* handle = dlopen(path, RTLD_LAZY); - if (NULL != (error = dlerror()) || NULL == handle) { + g_wakeup_engine_info[index].engine_handle = dlopen(path, RTLD_LAZY); + if (nullptr != (error = dlerror()) || nullptr == g_wakeup_engine_info[index].engine_handle) { MWR_LOGD("[ERROR] Fail to dlopen(%s), error(%s)", path, error); } else { g_wakeup_engine_info[index].interface.initialize = - (wakeup_engine_initialize)dlsym(handle, + (wakeup_engine_initialize)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_INITIALIZE); g_wakeup_engine_info[index].interface.deinitialize = - (wakeup_engine_deinitialize)dlsym(handle, + (wakeup_engine_deinitialize)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_DEINITIALIZE); g_wakeup_engine_info[index].interface.activate = - (wakeup_engine_activate)dlsym(handle, + (wakeup_engine_activate)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_ACTIVATE); g_wakeup_engine_info[index].interface.deactivate = - (wakeup_engine_deactivate)dlsym(handle, + (wakeup_engine_deactivate)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_DEACTIVATE); g_wakeup_engine_info[index].interface.add_wakeup_word = - (wakeup_engine_add_wakeup_word)dlsym(handle, + (wakeup_engine_add_wakeup_word)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_ADD_WAKEUP_WORD); g_wakeup_engine_info[index].interface.add_language = - (wakeup_engine_add_language)dlsym(handle, + (wakeup_engine_add_language)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_ADD_LANGUAGE); g_wakeup_engine_info[index].interface.set_language = - (wakeup_engine_set_language)dlsym(handle, + (wakeup_engine_set_language)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_SET_LANGUAGE); g_wakeup_engine_info[index].interface.update_manager_state = - (wakeup_engine_update_manager_state)dlsym(handle, + (wakeup_engine_update_manager_state)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_UPDATE_MANAGER_STATE); g_wakeup_engine_info[index].interface.set_audio_format = - (wakeup_engine_set_audio_format)dlsym(handle, + (wakeup_engine_set_audio_format)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_SET_AUDIO_FORMAT); g_wakeup_engine_info[index].interface.get_audio_format = - (wakeup_engine_get_audio_format)dlsym(handle, + (wakeup_engine_get_audio_format)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_GET_AUDIO_FORMAT); g_wakeup_engine_info[index].interface.feed_audio_data = - (wakeup_engine_feed_audio_data)dlsym(handle, + (wakeup_engine_feed_audio_data)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_FEED_AUDIO_DATA); g_wakeup_engine_info[index].interface.get_utterance_data_count = - (wakeup_engine_get_utterance_data_count)dlsym(handle, + (wakeup_engine_get_utterance_data_count)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_GET_UTTERANCE_DATA_COUNT); g_wakeup_engine_info[index].interface.get_utterance_data = - (wakeup_engine_get_utterance_data)dlsym(handle, + (wakeup_engine_get_utterance_data)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_GET_UTTERANCE_DATA); g_wakeup_engine_info[index].interface.set_assistant_specific_command = - (wakeup_engine_set_assistant_specific_command)dlsym(handle, + (wakeup_engine_set_assistant_specific_command)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND); g_wakeup_engine_info[index].interface.set_wakeup_event_callback = - (wakeup_engine_set_wakeup_event_callback)dlsym(handle, + (wakeup_engine_set_wakeup_event_callback)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_SET_WAKEUP_EVENT_CALLBACK); g_wakeup_engine_info[index].interface.set_speech_status_callback = - (wakeup_engine_set_speech_status_callback)dlsym(handle, + (wakeup_engine_set_speech_status_callback)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_SET_SPEECH_STATUS_CALLBACK); g_wakeup_engine_info[index].interface.set_error_callback = - (wakeup_engine_set_error_callback)dlsym(handle, + (wakeup_engine_set_error_callback)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_SET_ERROR_CALLBACK); g_wakeup_engine_info[index].interface.set_audio_data_require_status_callback = - (wakeup_engine_set_audio_data_require_status_callback)dlsym(handle, + (wakeup_engine_set_audio_data_require_status_callback)dlsym(g_wakeup_engine_info[index].engine_handle, MA_WAKEUP_ENGINE_FUNC_SET_AUDIO_DATA_REQUIRE_STATUS_CALLBACK); } strncpy(g_wakeup_engine_info[index].engine_path, path, _POSIX_PATH_MAX); + g_wakeup_engine_info[index].engine_path[_POSIX_PATH_MAX - 1] = '\0'; strncpy(g_wakeup_engine_info[index].engine_name, name, _POSIX_PATH_MAX); + g_wakeup_engine_info[index].engine_name[_POSIX_PATH_MAX - 1] = '\0'; g_wakeup_engine_info[index].active = false; /* We'll need to check vconf for enabled wakeup engines */ @@ -570,6 +569,10 @@ int wakeup_manager_deinitialize(void) if (g_wakeup_engine_info[loop].interface.deinitialize) { g_wakeup_engine_info[loop].interface.deinitialize(); } + if (g_wakeup_engine_info[loop].engine_handle) { + dlclose(g_wakeup_engine_info[loop].engine_handle); + g_wakeup_engine_info[loop].engine_handle = nullptr; + } } MWR_LOGD("[END]"); @@ -848,11 +851,23 @@ int wakeup_manager_process_event(int event, void* data, int len) /* Wakeup default assistant */ /* TODO: apply conversation timeout for selecting assistant here */ - wakeup_event_info event; - event.wakeup_word = nullptr; - event.wakeup_appid = g_wakeup_settings.get_default_assistant_appid().c_str(); + wakeup_event_info event_info; + std::string appid = g_wakeup_settings.get_default_assistant_appid(); + event_info.wakeup_appid = appid.c_str(); + event_info.wakeup_word = nullptr; + event_info.wakeup_language = nullptr; + event_info.wakeup_voice_id = nullptr; + event_info.wakeup_confidence_score = 0.0f; + + event_info.wakeup_start_time = 0L; + event_info.wakeup_end_time = 0L; + event_info.wakeup_time_valid = false; + + event_info.extra_data = nullptr; + event_info.extra_data_length = 0; + event_info.extra_data_description = nullptr; if (NULL != g_wakeup_event_cb) { - g_wakeup_event_cb(event, g_wakeup_event_user_data); + g_wakeup_event_cb(event_info, g_wakeup_event_user_data); } } } else if (event == MA_PLUGIN_EVENT_VOICE_KEY_RELEASED) { diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index c70db08..22c53cc 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -483,7 +483,7 @@ static int init_wakeup(void) for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) { if (g_maclient_info[loop].used && 0 < strlen(g_maclient_info[loop].appid)) { - if (g_maclient_info[loop].wakeup_engine) { + if (0 < strlen(g_maclient_info[loop].wakeup_engine)) { multi_assistant_service_plugin_set_assistant_wakeup_engine( g_maclient_info[loop].appid, g_maclient_info[loop].wakeup_engine); @@ -530,7 +530,6 @@ static void deinit_wakeup(void) if (0 != multi_assistant_service_plugin_deactivate()) { MAS_LOGE("Fail to ws deactivate"); - return -1; } int ret = mas_dbus_close_connection(); @@ -779,6 +778,7 @@ int mas_process_voice_key_event(bool pressed) } else { multi_assistant_service_plugin_process_event(MA_PLUGIN_EVENT_VOICE_KEY_RELEASED, NULL, 0); } + return 0; } bool service_app_create(void *data) -- 2.34.1