https://bugs.kde.org/show_bug.cgi?id=379669

Matt Whitlock <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]

--- Comment #56 from Matt Whitlock <[email protected]> ---
(In reply to RJVB from comment #55)
> The offending nullptr is the `this` pointer, the class instance
> itself. I don't see how that could happen except through a bug in the C++
> runtime...

Having this == nullptr is trivially easy to achieve. It doesn't imply a bug in
the C++ runtime.

struct Foo {
    void bar() { std::cout << this << std::endl; }
};
void example(Foo *foo_ptr) {
    foo_ptr->bar();
}

If you call example(nullptr), you will see 0 printed on stdout. It's only if
bar() is a *virtual* method that invoking it on a null pointer would crash
before reaching the member function body.

To be clear, invoking any member function on a null object pointer triggers
Undefined Behavior, and in fact more recent versions of G++ make the assumption
that this != nullptr (and will elide checks of that condition) by default, but
there are no actual machine instructions to assert that such precondition is
true, so you absolutely can get into the body of a non-virtual member function
called through a null pointer.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to