Skip to content
Snippets Groups Projects
Commit 1bed74fe authored by Filip Roséen's avatar Filip Roséen Committed by Hugo Beauzée-Luyssen
Browse files

nothrow new in cases where it maches intent


I wrote a hackish script to locate instances where new can throw
but where the original author has assumed that it will return
nullptr when there is a memory allocation problem.

In short, cases such as `ptr = new T; if (ptr) ...` has now
been changed to `ptr = new (std::nothrow) T; if (ptr) ...`.

Since a throwing `new` will always yield a non-nullptr pointer,
code that follows similar patterns to the previous example are
therefor redundant.

Example (from modules/access/dshow/filter.cpp):

    *ppEnum = new CaptureEnumMediaTypes( p_input, p_pin, this );

    if( *ppEnum == NULL )
      return E_OUTOFMEMORY; // unreachable, new will never return NULL

Fixed:

    *ppEnum = new (std::nothrow) CaptureEnumMediaTypes( p_input, p_pin, this );

    if( *ppEnum == NULL )
      return E_OUTOFMEMORY;

Signed-off-by: default avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent 465c14aa
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment