From: Ji-hoon Lee Date: Fri, 10 Apr 2020 02:00:08 +0000 (+0900) Subject: Fix defects detected by static analysis tool X-Git-Tag: submit/tizen/20200414.055516~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bb02643c98fa35f824f55a7bdbfd250ec016753e;p=platform%2Fcore%2Fuifw%2Fmulti-assistant-service.git Fix defects detected by static analysis tool Change-Id: Ief868cf1c63021d83370e4b29f0079cf7286d713 --- diff --git a/src/service_config.cpp b/src/service_config.cpp index 484b5e1..a86b491 100644 --- a/src/service_config.cpp +++ b/src/service_config.cpp @@ -291,6 +291,8 @@ int CServiceConfig::load_custom_wake_words(const char* app_id, char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN], char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]) { + const char delimeter = '|'; + /* Add 1 for additional pipe character */ char wakeup_words[MAX_WAKEUP_WORDS_NUM * (MAX_WAKEUP_WORD_LEN + 1)]; char wakeup_languages[MAX_WAKEUP_WORDS_NUM * (MAX_SUPPORTED_LANGUAGE_LEN + 1)]; @@ -324,8 +326,8 @@ int CServiceConfig::load_custom_wake_words(const char* app_id, char *language_end = NULL; int index = 0; while (index < MAX_WAKEUP_WORDS_NUM) { - word_end = strchrnul(word_start, '|'); - language_end = strchrnul(language_start, '|'); + word_end = strchrnul(word_start, delimeter); + language_end = strchrnul(language_start, delimeter); if ('\0' == *word_end || '\0' == *language_end) break; *word_end = '\0'; *language_end = '\0'; @@ -346,6 +348,7 @@ int CServiceConfig::save_custom_wake_words(const char* app_id, char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN], char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]) { + const char* delimeter = "|"; /* Add 1 for additional pipe character */ char wakeup_words[MAX_WAKEUP_WORDS_NUM * (MAX_WAKEUP_WORD_LEN + 1)]; char wakeup_languages[MAX_WAKEUP_WORDS_NUM * (MAX_SUPPORTED_LANGUAGE_LEN + 1)]; @@ -356,11 +359,11 @@ int CServiceConfig::save_custom_wake_words(const char* app_id, int wakeup_words_len = strlen(wakeup_words); strncat(wakeup_words, wakeup_word_storage[loop], sizeof(wakeup_words) - wakeup_words_len - 1); - strcat(wakeup_words, "|"); + strncat(wakeup_words, delimeter, strlen(delimeter)); int wakeup_languages_len = strlen(wakeup_languages); strncat(wakeup_languages, wakeup_language_storage[loop], sizeof(wakeup_languages) - wakeup_languages_len - 1); - strcat(wakeup_languages, "|"); + strncat(wakeup_languages, delimeter, strlen(delimeter)); } } wakeup_words[sizeof(wakeup_words) - 1] = '\0'; diff --git a/src/service_main.cpp b/src/service_main.cpp index 4628c15..8fd818a 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -586,19 +586,16 @@ int CServiceMain::initialize_service_plugin(void) if (0 == mServiceConfig.get_assistant_info(mas_assistant_info_cb, this)) { for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) { int inner_loop; - if (mClientInfo[loop].used && mClientInfo[loop].appid && - 0 < strlen(mClientInfo[loop].appid)) { + if (0 < strlen(mClientInfo[loop].appid)) { mServiceConfig.load_custom_wake_words(mClientInfo[loop].appid, mClientInfo[loop].wakeup_word, mClientInfo[loop].wakeup_language); - if (mClientInfo[loop].wakeup_engine && - 0 < strlen(mClientInfo[loop].wakeup_engine)) { + if (0 < strlen(mClientInfo[loop].wakeup_engine)) { mServicePlugin.set_assistant_wakeup_engine( mClientInfo[loop].appid, mClientInfo[loop].wakeup_engine); } for (inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) { - if (mClientInfo[loop].wakeup_word[inner_loop] && - 0 < strlen(mClientInfo[loop].wakeup_word[inner_loop])) { + if (0 < strlen(mClientInfo[loop].wakeup_word[inner_loop])) { MAS_LOGD("Registering wakeup word %s for app %s", mClientInfo[loop].wakeup_word[inner_loop], mClientInfo[loop].appid); if (0 != mServicePlugin.add_assistant_wakeup_word( @@ -610,8 +607,7 @@ int CServiceMain::initialize_service_plugin(void) } } for (inner_loop = 0; inner_loop < MAX_SUPPORTED_LANGUAGES_NUM; inner_loop++) { - if (mClientInfo[loop].supported_language[inner_loop] && - 0 < strlen(mClientInfo[loop].supported_language[inner_loop])) { + if (0 < strlen(mClientInfo[loop].supported_language[inner_loop])) { MAS_LOGD("Adding language %s for app %s", mClientInfo[loop].supported_language[inner_loop], mClientInfo[loop].appid); if (0 != mServicePlugin.add_assistant_language( diff --git a/src/service_plugin.cpp b/src/service_plugin.cpp index 4fbddce..f12323e 100644 --- a/src/service_plugin.cpp +++ b/src/service_plugin.cpp @@ -398,11 +398,10 @@ static void __error_cb(int error, const char* err_msg, void* user_data) { MAS_LOGD("[SUCCESS] __error_cb is called, error(%d), err_msg(%s)", error, err_msg); - CServiceIpcDbus* service_ipc = nullptr; CServicePlugin *plugin = static_cast(user_data); - if (plugin) { - service_ipc = plugin->get_service_ipc(); - } + if (nullptr == plugin) return; + + CServiceIpcDbus* service_ipc = plugin->get_service_ipc(); if (plugin->is_ui_panel_enabled() && service_ipc) { int ret = service_ipc->masc_ui_dbus_send_error_message(error, err_msg); if (0 != ret) { @@ -413,11 +412,10 @@ static void __error_cb(int error, const char* err_msg, void* user_data) static void __setting_changed_cb(void *user_data) { - CServiceMain* service_main = nullptr; CServicePlugin *plugin = static_cast(user_data); - if (plugin) { - service_main = plugin->get_service_main(); - } + if (nullptr == plugin) return; + + CServiceMain* service_main = plugin->get_service_main(); if (service_main) { service_main->mas_prelaunch_default_assistant(); service_main->mas_update_voice_key_support_mode(); @@ -429,13 +427,11 @@ static void __streaming_section_changed_cb(ma_audio_streaming_data_section_e sec { MAS_LOGD("[SUCCESS] __streaming_section_changed_cb is called, section(%d)", section); - CServiceIpcDbus *service_ipc = nullptr; - CServiceMain* service_main = nullptr; CServicePlugin *plugin = static_cast(user_data); - if (plugin) { - service_ipc = plugin->get_service_ipc(); - service_main = plugin->get_service_main(); - } + if (nullptr == plugin) return; + + CServiceIpcDbus *service_ipc = plugin->get_service_ipc(); + CServiceMain* service_main = plugin->get_service_main(); if (service_ipc && service_main) { int pid = service_main->mas_get_current_client_pid(); int ret = service_ipc->send_streaming_section_changed(pid, (int)section); @@ -449,13 +445,11 @@ static void __wakeup_engine_command_cb(mas_wakeup_engine_command_target_e target { MAS_LOGD("[SUCCESS] __wakeup_engine_command_cb is called, command(%s)", command); - CServiceIpcDbus *service_ipc = nullptr; - CServiceMain* service_main = nullptr; CServicePlugin *plugin = static_cast(user_data); - if (plugin) { - service_ipc = plugin->get_service_ipc(); - service_main = plugin->get_service_main(); - } + if (nullptr == plugin) return; + + CServiceIpcDbus *service_ipc = plugin->get_service_ipc(); + CServiceMain* service_main = plugin->get_service_main(); if (service_ipc && service_main) { int pid = service_main->mas_get_client_pid_by_appid(assistant_name); if (-1 != pid) { @@ -471,11 +465,10 @@ static void __wakeup_service_state_changed_cb(ma_service_state_e state, void* us { MAS_LOGD("[SUCCESS] __wakeup_service_state_changed_cb is called, state(%d)", state); - CServiceMain* service_main = nullptr; CServicePlugin *plugin = static_cast(user_data); - if (plugin) { - service_main = plugin->get_service_main(); - } + if (nullptr == plugin) return; + + CServiceMain* service_main = plugin->get_service_main(); if (service_main) { service_main->mas_set_current_service_state(state); } @@ -485,13 +478,11 @@ static void __wakeup_service_voice_key_status_changed_cb(ma_voice_key_status_e s { MAS_LOGD("[SUCCESS] __wakeup_service_voice_key_status_changed_cb is called, state(%d)", status); - CServiceIpcDbus *service_ipc = nullptr; - CServiceMain* service_main = nullptr; CServicePlugin *plugin = static_cast(user_data); - if (plugin) { - service_ipc = plugin->get_service_ipc(); - service_main = plugin->get_service_main(); - } + if (nullptr == plugin) return; + + CServiceIpcDbus *service_ipc = plugin->get_service_ipc(); + CServiceMain* service_main = plugin->get_service_main(); if (service_ipc && service_main) { int pid = service_main->mas_get_current_client_pid(); int ret = service_ipc->change_voice_key_status(pid, status);