File tree Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ internal struct DYNAMIC_TIME_ZONE_INFORMATION
61
61
62
62
internal const uint TIME_ZONE_ID_INVALID = 0xffffffff ;
63
63
internal const uint ERROR_NO_MORE_ITEMS = 259 ;
64
+ internal const uint ERROR_SUCCESS = 0 ;
64
65
65
66
[ DllImport ( "api-ms-win-core-timezone-l1-1-0.dll" ) ]
66
67
internal extern static uint EnumDynamicTimeZoneInformation ( uint dwIndex , out DYNAMIC_TIME_ZONE_INFORMATION lpTimeZoneInformation ) ;
@@ -349,7 +350,7 @@ internal static List<TimeZoneInfo> GetSystemTimeZonesWinRTFallback ()
349
350
try {
350
351
uint index = 0 ;
351
352
DYNAMIC_TIME_ZONE_INFORMATION dtzi ;
352
- while ( EnumDynamicTimeZoneInformation ( index ++ , out dtzi ) != ERROR_NO_MORE_ITEMS ) {
353
+ while ( EnumDynamicTimeZoneInformation ( index ++ , out dtzi ) == ERROR_SUCCESS ) {
353
354
var timeZoneInfo = TryCreateTimeZone ( dtzi ) ;
354
355
if ( timeZoneInfo != null )
355
356
result . Add ( timeZoneInfo ) ;
@@ -358,8 +359,6 @@ internal static List<TimeZoneInfo> GetSystemTimeZonesWinRTFallback ()
358
359
// EnumDynamicTimeZoneInformation() might not be available.
359
360
}
360
361
361
- if ( result . Count == 0 )
362
- result . Add ( Local ) ;
363
362
return result ;
364
363
}
365
364
}
Original file line number Diff line number Diff line change @@ -787,6 +787,10 @@ public static ReadOnlyCollection<TimeZoneInfo> GetSystemTimeZones ()
787
787
if ( systemTimeZones == null ) {
788
788
var tz = new List < TimeZoneInfo > ( ) ;
789
789
GetSystemTimeZonesCore ( tz ) ;
790
+ // Don't want to return an empty list if we can help it
791
+ // but we don't want to stack overflow via a CreateLocal loop
792
+ if ( tz . Count == 0 && local != null )
793
+ tz . Add ( Local ) ;
790
794
Interlocked . CompareExchange ( ref systemTimeZones , new ReadOnlyCollection < TimeZoneInfo > ( tz ) , null ) ;
791
795
}
792
796
You can’t perform that action at this time.
0 commit comments