From 0cbe5463e6c848099aa4578ee839aac0f8e82de7 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 14 Jun 2021 19:18:15 +0800 Subject: [PATCH] [td-4692]: error in system locale set caused client crash. --- src/client/src/tscSystem.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index bd79f81846..c602d1bfcc 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -288,16 +288,23 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { if (strlen(tsLocale) == 0) { // locale does not set yet char* defaultLocale = setlocale(LC_CTYPE, ""); + + // The locale of the current OS does not be set correctly, so the default locale cannot be acquired. + if (defaultLocale == NULL) { + uError("failed to get default locale, please set the correct locale in current OS"); + return -1; + } + tstrncpy(tsLocale, defaultLocale, TSDB_LOCALE_LEN); } // set the user specified locale char *locale = setlocale(LC_CTYPE, pStr); - if (locale != NULL) { + if (locale != NULL) { // failed to set the user specified locale tscInfo("locale set, prev locale:%s, new locale:%s", tsLocale, locale); cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; - } else { // set the user-specified localed failed, use default LC_CTYPE as current locale + } else { // set the user specified locale failed, use default LC_CTYPE as current locale locale = setlocale(LC_CTYPE, tsLocale); tscInfo("failed to set locale:%s, current locale:%s", pStr, tsLocale); } -- GitLab