Avoid reusing variables for retrieving configuration values 74/290674/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Mon, 6 Mar 2023 12:13:51 +0000 (21:13 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Thu, 30 Mar 2023 11:43:04 +0000 (20:43 +0900)
Change-Id: I5bbe4dcf92783f9266dc3b9c30aad0cbcabd49d2

plugins/wakeup-manager/src/wakeup_settings.cpp

index 327e07c635e4e48c3c9ab7700ca7bc836829cea2..6047fe7352c67670179d7de96d725e71d0cef664 100644 (file)
@@ -174,48 +174,48 @@ static void wakeup_setting_enabled_wake_word_detection_changed_cb(keynode_t* nod
 
 void CWakeupSettings::initialize(map<string, string> custom_keys)
 {
-       int vconf_ret;
-       char *vconf_str;
-       int vconf_bool;
-       double vconf_double;
+       int vconf_ret = 0;
 
        mCustomVconfKeys.clear();
        mCustomVconfKeys = custom_keys;
 
-       vconf_str = vconf_get_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID].c_str());
-       if (vconf_str) {
-               mDefaultAssistantAppid = vconf_str;
+       char *default_assistant = vconf_get_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID].c_str());
+       if (default_assistant) {
+               mDefaultAssistantAppid = default_assistant;
                MWR_LOGD("default_assistant_appid : %s", mDefaultAssistantAppid.c_str());
                for (const auto& observer : mObservers) {
                        if (observer) {
-                               if (!observer->on_default_assistant_appid_changed(vconf_str)) {
+                               if (!observer->on_default_assistant_appid_changed(default_assistant)) {
                                        LOGW("[Settings WARNING] One of the observer returned false");
                                }
                        }
                }
-               free(vconf_str);
-               vconf_str = nullptr;
+               free(default_assistant);
+               default_assistant = nullptr;
        }
-       vconf_ret = vconf_get_bool(WAKEUP_SETTINGS_KEY_UI_PANEL_ENABLED, &vconf_bool);
+       int ui_panel_enabled = 0;
+       vconf_ret = vconf_get_bool(WAKEUP_SETTINGS_KEY_UI_PANEL_ENABLED, &ui_panel_enabled);
        if (0 == vconf_ret) {
-               mUiPanelEnabled = vconf_bool;
+               mUiPanelEnabled = ui_panel_enabled;
                MWR_LOGD("ui_panel_enabled : %s", (mUiPanelEnabled ? "true" : "false"));
        }
-       vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_CONVERSATION_TIMEOUT, &vconf_double);
+       double conversation_timeout = 0.0;
+       vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_CONVERSATION_TIMEOUT, &conversation_timeout);
        if (0 == vconf_ret) {
-               mConversationTimeout = vconf_double;
+               mConversationTimeout = conversation_timeout;
                MWR_LOGD("conversation_timeout : %f", mConversationTimeout);
        }
-       vconf_ret = vconf_get_bool(WAKEUP_SETTINGS_KEY_MULTIPLE_MODE, &vconf_bool);
+       int multiple_mode = 0;
+       vconf_ret = vconf_get_bool(WAKEUP_SETTINGS_KEY_MULTIPLE_MODE, &multiple_mode);
        if (0 == vconf_ret) {
-               mMultipleMode = vconf_bool;
+               mMultipleMode = multiple_mode;
                MWR_LOGD("multiple_mode : %s", (mMultipleMode ? "true" : "false"));
        }
        if (true == mMultipleMode) {
-               vconf_str = vconf_get_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS].c_str());
-               if (vconf_str) {
+               char *enabled_assistants = vconf_get_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS].c_str());
+               if (enabled_assistants) {
                        string token;
-                       istringstream iss(vconf_str);
+                       istringstream iss(enabled_assistants);
                        mEnabledAssistants.clear();
                        while (getline(iss, token, ';')) {
                                mEnabledAssistants.push_back(token);
@@ -228,16 +228,16 @@ void CWakeupSettings::initialize(map<string, string> custom_keys)
                                        }
                                }
                        }
-                       free(vconf_str);
-                       vconf_str = nullptr;
+                       free(enabled_assistants);
+                       enabled_assistants = nullptr;
                }
        }
-       vconf_str = vconf_get_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_WAKE_WORD_DETECTION_ENABLED].c_str());
-       if (vconf_str) {
+       char *wake_word_detection_enabled = vconf_get_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_WAKE_WORD_DETECTION_ENABLED].c_str());
+       if (wake_word_detection_enabled) {
                Json::Reader reader;
                Json::Value root;
                mWakeWordDisabledAssistants.clear();
-               if (!reader.parse(vconf_str, root)) {
+               if (!reader.parse(wake_word_detection_enabled, root)) {
                        LOGW("[Settings WARNING] Failed to parse Json : %s", reader.getFormattedErrorMessages().c_str());
                } else {
                        auto member = root.getMemberNames();
@@ -248,45 +248,47 @@ void CWakeupSettings::initialize(map<string, string> custom_keys)
                                }
                        }
                }
-               free(vconf_str);
-               vconf_str = nullptr;
+               free(wake_word_detection_enabled);
+               wake_word_detection_enabled = nullptr;
        }
-       vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_DELAY, &vconf_double);
+       double wakeup_policy_delay = 0.0;
+       vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_DELAY, &wakeup_policy_delay);
        if (0 == vconf_ret) {
-               mWakeupPolicyDelay = vconf_double;
+               mWakeupPolicyDelay = wakeup_policy_delay;
                MWR_LOGD("conversation_timeout : %f", mWakeupPolicyDelay);
        }
-       vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_PRIORITY);
-       if (vconf_str) {
+       char *wakeup_policy_priority = vconf_get_str(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_PRIORITY);
+       if (wakeup_policy_priority) {
                string token;
-               istringstream iss(vconf_str);
+               istringstream iss(wakeup_policy_priority);
                mWakeupPolicyPriority.clear();
                while (getline(iss, token, ';')) {
                        mWakeupPolicyPriority.push_back(token);
                        MWR_LOGD("wakeup_policy_priority : %s", token.c_str());
                }
-               free(vconf_str);
-               vconf_str = nullptr;
+               free(wakeup_policy_priority);
+               wakeup_policy_priority = nullptr;
        }
-       vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_STREAMING_DURATION_MAX, &vconf_double);
+       double streaming_duration_max = 0.0;
+       vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_STREAMING_DURATION_MAX, &streaming_duration_max);
        if (0 == vconf_ret) {
-               mStreamingDurationMax = vconf_double;
+               mStreamingDurationMax = streaming_duration_max;
                MWR_LOGD("streaming_duration_max : %f", mStreamingDurationMax);
        }
 #ifdef ENABLE_VOICE_INPUT_LANGUAGE_SETTINGS
-       vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE);
-       if (vconf_str) {
-               mVoiceInputLanguage = vconf_str;
+       char *voice_input_language = vconf_get_str(WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE);
+       if (voice_input_language) {
+               mVoiceInputLanguage = voice_input_language;
                MWR_LOGD("voice input language : %s", mVoiceInputLanguage.c_str());
                for (const auto& observer : mObservers) {
                        if (observer) {
-                               if (!observer->on_voice_input_language_changed(vconf_str)) {
+                               if (!observer->on_voice_input_language_changed(voice_input_language)) {
                                        LOGW("[Settings WARNING] One of the observer returned false");
                                }
                        }
                }
-               free(vconf_str);
-               vconf_str = nullptr;
+               free(voice_input_language);
+               voice_input_language = nullptr;
        }
 #endif