Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero initialize tm struct. #139

Merged
merged 1 commit into from
Apr 18, 2023
Merged

Zero initialize tm struct. #139

merged 1 commit into from
Apr 18, 2023

Conversation

bradleybauer
Copy link
Contributor

@bradleybauer bradleybauer commented Apr 18, 2023

See here for what motivated this change.

@KjellKod
Copy link
Owner

KjellKod commented Apr 18, 2023

This seems fine.

I'll go ahead and merge it and also like to call out that this is mostly a valgrind nonsense issue.
The difference is that with this fix all values are default initialized, vs previously the first value was zero initialized and the rest was default initialized.

This would yield identical outputs

    struct tm tm1{};
    std::cout 
        << "tm_sec: " << tm1.tm_sec << ", "
        << "\ntm_min: " << tm1.tm_min << ", "
        << "\ntm_hour: " << tm1.tm_hour << ", "
        << "\ntm_mday: " << tm1.tm_mday << ", "
        << "\ntm_mon: " << tm1.tm_mon << ", "
        << "\ntm_year: " << tm1.tm_year << ", "
        << "\ntm_wday: " << tm1.tm_wday << ", "
        << "\ntm_yday: " << tm1.tm_yday << ", "
        << "\ntm_isdst: " << tm1.tm_isdst << std::endl;
        
    struct tm tm2 = {0};
   std::cout 
        << "\ntm2\ntm_sec: " << tm2.tm_sec << ", "
        << "\ntm_min: " << tm2.tm_min << ", "
        << "\ntm_hour: " << tm2.tm_hour << ", "
        << "\ntm_mday: " << tm2.tm_mday << ", "
        << "\ntm_mon: " << tm2.tm_mon << ", "
        << "\ntm_year: " << tm2.tm_year << ", "
        << "\ntm_wday: " << tm2.tm_wday << ", "
        << "\ntm_yday: " << tm2.tm_yday << ", "
        << "\ntm_isdst: " << tm2.tm_isdst << std::endl;    
        

@KjellKod
Copy link
Owner

Fixing valgrind complaint. The fix is essentially a no-op change

@KjellKod KjellKod merged commit 05f76fc into KjellKod:master Apr 18, 2023
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