Skip to content

Commit

Permalink
Do not return pointer to local from get_timezone
Browse files Browse the repository at this point in the history
The pointed at variable was also a wchar_t array, not char, and so also
convert the contents to UTF-8. The static buffer is sized for the worst
case and the conversion will always succeed.
  • Loading branch information
skeeto committed Jan 17, 2025
1 parent 1ed0333 commit 126032b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,15 @@ const char *get_timezone(const struct tm *local_time)
{
#ifdef _WIN32
// Windows-specific code
static char namebuf[32*3]; // worst case for UTF-8
TIME_ZONE_INFORMATION tz_info;
wchar_t *name = tz_info.StandardName;
if (GetTimeZoneInformation(&tz_info) == TIME_ZONE_ID_DAYLIGHT && local_time->tm_isdst > 0)
{
return tz_info.DaylightName; // DST time zone name
}
else
{
return tz_info.StandardName; // Standard time zone name
name = tz_info.DaylightName;
}
WideCharToMultiByte(CP_UTF8, 0, name, -1, namebuf, sizeof(namebuf), NULL, NULL);
return namebuf;
#else
// Unix-like systems (Linux/macOS) code
extern char *tzname[2]; // tzname[0] is standard, tzname[1] is DST
Expand Down

0 comments on commit 126032b

Please sign in to comment.