Skip to content

Fix inverted null check in time_zone_name_win.cc#340

Open
yukawa wants to merge 1 commit intogoogle:masterfrom
yukawa:fix_icu_load_null_check
Open

Fix inverted null check in time_zone_name_win.cc#340
yukawa wants to merge 1 commit intogoogle:masterfrom
yukawa:fix_icu_load_null_check

Conversation

@yukawa
Copy link
Contributor

@yukawa yukawa commented Mar 15, 2026

This commit follows up the previous commit (27ca173), which aimed to improve the code but ended up introducing an inverted null check in time_zone_name_win.cc. As a result, LoadIcuGetTimeZoneIDForWindowsID() currently returns nullptr when it should be returning a valid time zone ID.

This is also a preparation for implementing TimeZoneIf with Windows time APIs (#328).

AsProcAddress<ucal_getTimeZoneIDForWindowsID_func>(
icu_dll, "ucal_getTimeZoneIDForWindowsID");
if (ucal_getTimeZoneIDForWindowsIDRef != nullptr) {
if (ucal_getTimeZoneIDForWindowsIDRef == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with the change, of course, but it does seem to indicate that we don't have anything that tests whether GetWindowsLocalTimeZone() works.

Copy link
Contributor Author

@yukawa yukawa Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. The existing fallback chain in local_time_zone() makes it difficult for the test to actually fail. I've added a dedicated unit test in cbbfd28. Does it make sense?

@yukawa yukawa force-pushed the fix_icu_load_null_check branch 2 times, most recently from e33561c to cbbfd28 Compare March 23, 2026 02:08
CMakeLists.txt Outdated
Comment on lines +164 to +167
set(CCTZ_TESTS civil_time_test time_zone_format_test time_zone_lookup_test)
if(WIN32)
list(APPEND CCTZ_TESTS time_zone_name_win_test)
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps separate list(APPEND CCTZ_TESTS ...) calls would be best factored out to after the corresponding add_test() calls? That would make each block its own separate unit, and remove the need for the extra if(WIN32) conditional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Done in 841a08a.

@yukawa yukawa force-pushed the fix_icu_load_null_check branch from cbbfd28 to 841a08a Compare March 23, 2026 18:54
HMODULE icu_dll =
::LoadLibraryExW(L"icu.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (icu_dll != nullptr) {
const std::string tz = GetWindowsLocalTimeZone();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps factor this repeated statement out of the conditional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in d09a3fd.

This commit follows up the previous commit [1], which aimed to improve
the code but ended up introducing an inverted null check in
time_zone_name_win.cc. As a result, LoadIcuGetTimeZoneIDForWindowsID()
currently returns nullptr when it should be returning a valid time zone
ID.

A unit test is also added, as the fallback chain in local_time_zone()
makes it difficult to verify the behavior of
LoadIcuGetTimeZoneIDForWindowsID() in isolation. The test ensures that
the function correctly returns a valid time zone ID on Windows.

This is also a preparation for implementing TimeZoneIf with Windows time
APIs (google#328).

[1] 27ca173
@yukawa yukawa force-pushed the fix_icu_load_null_check branch from 841a08a to d09a3fd Compare March 23, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants