Skip to content

[libc++] std::shared_ptr::reset() should catch being reset to its own pointer #79083

Open
@ldionne

Description

@ldionne

https://compiler-explorer.com/z/s58er4o4z

#include <memory>

int main() {
    auto p = std::make_shared<int>(42);
    p.reset(p.get()); // Incorrect use of reset
}

libstdc++ catches that with

Assertion '__p == nullptr || __p != _M_ptr' failed.

I think it would be really easy to add this check in libc++ too.

Metadata

Metadata

Assignees

Labels

hardeningIssues related to the hardening effortlibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions