ETLCPP / etl

Embedded Template Library
https://www.etlcpp.com
MIT License
2.05k stars 373 forks source link

etl::unique_ptr::reset() can call deleter with nullptr argument #766

Closed multiplemonomials closed 9 months ago

multiplemonomials commented 9 months ago

Hi, I noticed what seems to be an issue when implementing a custom deleter to be used with a unique_ptr.

In most cases (e.g. here), the pointer is checked and is not passed to the deleter if it's nullptr. However, that check is missing here in reset(). So, if you assign a valid unique_ptr to an empty unique_ptr, the deleter is called on a null pointer.

Or, is this intended behavior, and the deleter is simply supposed to ignore null pointers when called on them? If that's the case then this isn't a bug, though maybe the behavior should be made clearer in the docs.

multiplemonomials commented 9 months ago

Thanks for the quick fix!