Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couple of Null check corrections #44

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/converter/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,26 @@ BOOST_PYTHON_DECL PyObject* registration::to_python(void const volatile* source)

throw_error_already_set();
}

return source == 0
? incref(Py_None)
: this->m_to_python(const_cast<void*>(source));
else
{
return source == 0
? incref(Py_None)
: this->m_to_python(const_cast<void*>(source));
}
}

namespace
{
template< typename T >
void delete_node( T* node )
{
if( !!node && !!node->next )
if( node && node->next )
{
delete_node( node->next );
delete node;
delete node;
}
else if( node )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are checking if node is not null two times instead of one. And the delete operator is a no-op when the pointer is null, this whole thing can be simply written as:

if (node != 0)
    delete_node(node->next);
delete node;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree delete NULL is safe.

delete node;
}
}

Expand Down