#176 DeepCopy::Clone() dereferences null pointer

closed-fixed
None
5
2011-09-07
2011-03-19
Anonymous
No

The DeepCopy::Clone() function in SmartPtr.h doesn't check whether the pointer being dereferenced is null, which leads to undefined behaviour. Example of code causing an error:

#include <Loki/SmartPtr.h>

struct Foo {
Foo* Clone() const { return new Foo(*this); }
int someValue;
};

int main() {
typedef Loki::SmartPtr<Foo, Loki::DeepCopy> Ptr;

Ptr nullPtr; // points to nothing
Ptr ptr(nullPtr); // error!
}

Discussion

  • Richard Sposato

    Richard Sposato - 2011-09-07

    Fixed in revision 1094.
    Added calls to KP:OnDereference to check parameter for non-null.
    Added code to test/SmartPtr project to check for null pointers when using DeepCopy policy.

    Test project revisions are 1095 and 1096.

     
  • Richard Sposato

    Richard Sposato - 2011-09-07
    • assigned_to: nobody --> rich_sposato
    • status: open --> closed-fixed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks