New issue
Advanced search Search tips

Issue 786188 link

Starred by 0 users

Issue metadata

Status: Untriaged
Owner: ----
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

base::AsWeakPtr crashes on null pointer

Project Member Reported by fdegros@chromium.org, Nov 16 2017

Issue description

https://cs.chromium.org/chromium/src/base/memory/weak_ptr.h?l=373&rcl=6f07ce6c4c237245bb0392c632c7847b29000ee6

base::AsWeakPtr(p) crashes if passed a null pointer.

This is surprising and undocumented. I would have expected it to return a null WeakPtr.

 
Components: Internals>Core
The function template

template <typename Derived>                                                                                                                                   
WeakPtr<Derived> AsWeakPtr(Derived* t)

looks and feels like a pointer cast operator, similar to static_cast, dynamic_cast or std::static_pointer_cast.

All these pointer cast operators are null-friendly.

Our WeakPtr's conversion constructor is also null-friendly: it converts a null WeakPtr<U> to a null WeakPtr<T>.

However, AsWeakPtr(Derived*) crashes on a null pointer. This is surprising and undocumented. This feels more like an oversight than a deliberate feature. And this can easily be fixed.
Cc: -dcheng@chromium.org
Owner: ----

Sign in to add a comment