Describe the refactoring action
The codebase uses C++'s new but handles allocation failures as if it were C's malloc by checking if the returned pointer is NULL, while new in C++ throws a std::bad_alloc if it fails, unless the call is marked with std::no_throw.
Possible actions
Do nothing: If we leave the NULL checking code as is then it just stays as dead code. This is not a particularly high-severity issue IMO
Add std::no_throw to the calls to new. This will keep the current error handling code as new will return NULL on failure.
Remove the error handling code: Allocation failure means something else has gone terribly wrong and there is little that can be done to handle a bad_alloc [1][2], so might as well let it go uncaught and terminate the program. We can replace some of the calls to new with smart pointers where the API permits.
An overview of misuses:
Collected by a Python script, may not be complete
Describe the refactoring action The codebase uses C++'s
new
but handles allocation failures as if it were C'smalloc
by checking if the returned pointer is NULL, whilenew
in C++ throws a std::bad_alloc if it fails, unless the call is marked with std::no_throw.Possible actions
std::no_throw
to the calls tonew
. This will keep the current error handling code as new will return NULL on failure.An overview of misuses: Collected by a Python script, may not be complete