From dcad420127669d489cef8109b61fb7a1902189e2 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 21 Jun 2021 02:45:30 +0800 Subject: [PATCH] libc/time: Update g_lcl_tzname only after the success Signed-off-by: Xiang Xiao Change-Id: I0117c5b43bee3affb36d118e0b97f6dd7137080b --- libs/libc/time/lib_localtime.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/libc/time/lib_localtime.c b/libs/libc/time/lib_localtime.c index 647ce51542..d3fc99b235 100644 --- a/libs/libc/time/lib_localtime.c +++ b/libs/libc/time/lib_localtime.c @@ -2532,19 +2532,12 @@ void tzset(void) goto out; } - g_lcl_isset = strlen(name) < sizeof g_lcl_tzname; - if (g_lcl_isset) - { - strcpy(g_lcl_tzname, name); - } - if (lclptr == NULL) { lclptr = lib_malloc(sizeof *lclptr); if (lclptr == NULL) { - settzname(); /* all we can do */ - goto out; + goto tzname; } } @@ -2565,11 +2558,18 @@ void tzset(void) if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0) { gmtload(lclptr); + goto tzname; } } - settzname(); + g_lcl_isset = strlen(name) < sizeof g_lcl_tzname; + if (g_lcl_isset) + { + strcpy(g_lcl_tzname, name); + } +tzname: + settzname(); out: tz_semgive(&g_lcl_sem); }