Skip to content

Commit aac20d3

Browse files
committed
Native (Windows): Fix a bug with DST check being wrong sometimes
Some structures were not initialized, and so had garbage in unitialized fields.
1 parent cc6d98d commit aac20d3

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

core/nativeMain/cinterop/cpp/windows.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static void repopulate_timezone_cache(
8989
return;
9090
}
9191
cache.clear();
92-
DYNAMIC_TIME_ZONE_INFORMATION dtzi;
92+
DYNAMIC_TIME_ZONE_INFORMATION dtzi{};
9393
next_flush = current_time + CACHE_INVALIDATION_TIMEOUT;
9494
for (DWORD dwResult = 0, i = 0; dwResult != ERROR_NO_MORE_ITEMS; ++i) {
9595
dwResult = EnumDynamicTimeZoneInformation(i, &dtzi);
@@ -135,17 +135,14 @@ representing a proper date at a given year.
135135
*/
136136
static void get_transition_date(int year, const SYSTEMTIME& src, SYSTEMTIME& dst)
137137
{
138-
// if the year is 0, this is the absolute time.
138+
dst = src;
139+
// if the year is not 0, this is the absolute time.
139140
if (src.wYear != 0) {
140-
dst = src;
141141
return;
142142
}
143-
// otherwise, the transition happens yearly...
143+
/* otherwise, the transition happens yearly at the specified month, hour,
144+
and minute at the specified day of the week. */
144145
dst.wYear = year;
145-
// at the specified month, hour, and minute.
146-
dst.wMonth = src.wMonth; dst.wHour = src.wHour; dst.wMinute = src.wMinute;
147-
// at the specified day of the week.
148-
dst.wDayOfWeek = src.wDayOfWeek;
149146
// The number of the occurrence of the specified day of week in the month,
150147
// or the special value "5" to denote the last such occurrence.
151148
unsigned int dowOccurrenceNumber = src.wDay;
@@ -248,7 +245,7 @@ static bool is_daylight_time(
248245
static int offset_at_systime(DYNAMIC_TIME_ZONE_INFORMATION& dtzi,
249246
const SYSTEMTIME& systime)
250247
{
251-
TIME_ZONE_INFORMATION tzi;
248+
TIME_ZONE_INFORMATION tzi{};
252249
bool result = GetTimeZoneInformationForYear(systime.wYear, &dtzi, &tzi);
253250
if (!result) {
254251
return INT_MAX;

0 commit comments

Comments
 (0)