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

Calls to std::weak_ptr<T>::lock() should always be checked #1078

Open
agarny opened this issue Jan 5, 2023 · 0 comments
Open

Calls to std::weak_ptr<T>::lock() should always be checked #1078

agarny opened this issue Jan 5, 2023 · 0 comments

Comments

@agarny
Copy link
Contributor

agarny commented Jan 5, 2023

Dealing with branch coverage, I have seen many instances of code like this:

auto sharedPtr = weakPtr.lock();

if (sharedPtr != nullptr) {
    ...
}

In 99.9% of cases, sharedPtr != nullptr is always true, which means that our branch coverage can never be 100% and that is completely fine.

However, after a very quick look at the overall codebase, I could see that there are cases where we do NOT check for sharedPtr != nullptr and that is (very) bad practice. So, if anything, we really ought to ensure that our whole codebase always check for sharedPtr != nullptr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant