From 72196c24f371400d1aa99840109be7ecfd56b990 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Fri, 14 Oct 2022 11:58:40 +0900 Subject: [PATCH] Fix static anlysis issues - Contents: This patch includes these changes: - Remove equality check of floating point values. - Remove TOC-TOU problem. - Make blocks for code in switch-case statements. - Remove arguments from void parameter function. Change-Id: I119d15f3a600a9cf51e5b9150a69530f782cd04b Signed-off-by: Suyeon Hwang --- client/tts.c | 13 +++++++------ client/tts_core.c | 6 +++--- common/tts_config_mgr.c | 2 +- common/tts_config_parser.c | 10 +++------- server/BackgroundVolume.cpp | 6 +----- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/client/tts.c b/client/tts.c index 739b7c3..b131e0b 100644 --- a/client/tts.c +++ b/client/tts.c @@ -325,21 +325,20 @@ int tts_destroy(tts_h tts) switch (tts_client_get_current_state(client)) { case TTS_STATE_PAUSED: case TTS_STATE_PLAYING: - case TTS_STATE_READY: + case TTS_STATE_READY: { if (0 != tts_core_unprepare(client)) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare"); } tts_client_set_current_state(client, TTS_STATE_CREATED); - case TTS_STATE_CREATED: + } + case TTS_STATE_CREATED: { /* Unset registered callbacks */ tts_client_unset_all_cb(client); int thread_count = ecore_thread_active_get(); SLOG(LOG_INFO, TAG_TTSC, "[INFO] Active thread count: %d", thread_count); - int cnt = 0; - while (0 < thread_count) { + for (int cnt = 0; 0 < thread_count; cnt++) { usleep(50000); - cnt++; if (30 == cnt) { SLOG(LOG_WARN, TAG_TTSC, "[WARNNING] Thread is blocked, %d", thread_count); break; @@ -356,10 +355,12 @@ int tts_destroy(tts_h tts) tts_client_destroy(tts); break; - default: + } + default: { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid"); return TTS_ERROR_INVALID_PARAMETER; } + } unsigned int num_of_client = tts_client_get_size(); SLOG(LOG_ERROR, TAG_TTSC, "[INFO] num_of_client(%u)", num_of_client); diff --git a/client/tts_core.c b/client/tts_core.c index 66b0ee0..f3b9959 100644 --- a/client/tts_core.c +++ b/client/tts_core.c @@ -1189,7 +1189,7 @@ int tts_core_add_text(tts_client_s* client, const char* text, const char* langua RETVM_IF(NULL == text || NULL == utt_id, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Parameter is invalid."); RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); - bool is_launched = __is_engine_launched(tts_client_get_mode(client)); + bool is_launched = __is_engine_launched(); SLOG(LOG_ERROR, TAG_TTSC, "[INFO] tts engine is launched(%d)", is_launched); tts_client_set_repeat_text(client, text); @@ -1210,7 +1210,7 @@ int tts_core_play(tts_client_s* client) { RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); - bool is_launched = __is_engine_launched(tts_client_get_mode(client)); + bool is_launched = __is_engine_launched(); SLOG(LOG_ERROR, TAG_TTSC, "[INFO] tts engine is launched(%d)", is_launched); return __request_play(client); @@ -1220,7 +1220,7 @@ int tts_core_stop(tts_client_s* client) { RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); - bool is_launched = __is_engine_launched(tts_client_get_mode(client)); + bool is_launched = __is_engine_launched(); SLOG(LOG_ERROR, TAG_TTSC, "[INFO] tts engine is launched(%d)", is_launched); unsigned int uid = tts_client_get_uid(client); diff --git a/common/tts_config_mgr.c b/common/tts_config_mgr.c index 4d50896..8cbe6ab 100644 --- a/common/tts_config_mgr.c +++ b/common/tts_config_mgr.c @@ -521,7 +521,7 @@ Eina_Bool tts_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handl } } - if (-1 != bg_volume_ratio) { + if (0.0 <= bg_volume_ratio) { config_info.bg_volume_ratio = bg_volume_ratio; SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "background volume ratio change(%lf)", config_info.bg_volume_ratio); diff --git a/common/tts_config_parser.c b/common/tts_config_parser.c index 6e33df2..4360f9c 100644 --- a/common/tts_config_parser.c +++ b/common/tts_config_parser.c @@ -733,14 +733,9 @@ static int __set_value_into_configuration(const char* key, const char* value) static void __save_configuration(xmlDocPtr config_doc) { - if (0 != access(TTS_CONFIG, F_OK)) { - SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG); - return; - } - int ret = xmlSaveFile(TTS_CONFIG, config_doc); if (0 > ret) { - SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : file(%s), ret(%d)", TTS_CONFIG, ret); } else { static FILE* pFile; pFile = fopen(TTS_CONFIG, "r"); @@ -1156,7 +1151,8 @@ int tts_parser_reset() char* engine_id = vconf_get_str(TTS_ENGINE_DB_DEFAULT); if (engine_id) { - __set_value_into_configuration(TTS_TAG_CONFIG_ENGINE_ID, engine_id); + int ret = __set_value_into_configuration(TTS_TAG_CONFIG_ENGINE_ID, engine_id); + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Set engine ID into xml. engine_id(%s), ret(%d/%s)", engine_id, ret, get_error_message(ret)); free(engine_id); } __save_configuration(g_config_doc); diff --git a/server/BackgroundVolume.cpp b/server/BackgroundVolume.cpp index 564ffdf..d5f81e1 100644 --- a/server/BackgroundVolume.cpp +++ b/server/BackgroundVolume.cpp @@ -114,11 +114,7 @@ BackgroundVolume::~BackgroundVolume() void BackgroundVolume::setVolumeRatio(double ratio) { - if (__volumeRatio.load() == ratio) { - SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Volume is not changed (%lf).", ratio); - return; - } - + SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Volume is changed from (%lf) to (%lf).", __volumeRatio.load(), ratio); __volumeRatio = ratio; ecore_main_loop_thread_safe_call_async(modifyVolumeOnMainThread, static_cast(this)); } -- 2.7.4