From 95767b2831abca02b2c1befc35a397a5ed95ffb1 Mon Sep 17 00:00:00 2001 From: "jinwang.an" Date: Fri, 31 Jan 2020 18:28:51 +0900 Subject: [PATCH] Fix to get locale language and country data Change-Id: I6159f3232c69e413e1ac79498373901af557c316 Signed-off-by: jinwang.an --- src/system_setting_platform.c | 20 ++++++++++++++++---- unit_test/src/unit_test.c | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/system_setting_platform.c b/src/system_setting_platform.c index aded30a..ddbb45b 100644 --- a/src/system_setting_platform.c +++ b/src/system_setting_platform.c @@ -1374,9 +1374,15 @@ int system_setting_get_locale_country(system_settings_key_e key, void **value) /* parsing validation */ /* en_US.UTF-8 */ - char arr[20]; + char arr[21] = {0,}; snprintf(arr, 20, "%s", vconf_value); - arr[5] = '\0'; + for (int i = 0; i < strlen(arr); i++) { + if ('.' == arr[i]) { + arr[i] = 0; + SETTING_TRACE("replace . to NULL : %d", i); + break; + } + } *value = strdup(arr); free(vconf_value); vconf_value = NULL; @@ -1427,9 +1433,15 @@ int system_setting_get_locale_language(system_settings_key_e key, void **value) /* parsing validation */ /* en_US.UTF-8 */ - char arr[20]; + char arr[21] = {0,}; snprintf(arr, 20, "%s", vconf_value); - arr[5] = '\0'; + for (int i = 0; i < strlen(arr); i++) { + if ('.' == arr[i]) { + arr[i] = 0; + SETTING_TRACE("replace . to NULL : %d", i); + break; + } + } *value = strdup(arr); free(vconf_value); vconf_value = NULL; diff --git a/unit_test/src/unit_test.c b/unit_test/src/unit_test.c index 7785fdc..cc55f7d 100644 --- a/unit_test/src/unit_test.c +++ b/unit_test/src/unit_test.c @@ -1968,6 +1968,7 @@ RETTYPE utc_system_settings_set_value_string_p4(void) if (ret_country != NULL && 0 == strcmp(ret_country, new_country)) { assert(1); } else { + printf("ret:%s new:%s not same\n", ret_country, new_country); assert(0); } -- 2.7.4