• Filip Roséen's avatar
    nothrow new in cases where it maches intent · 1bed74fe
    Filip Roséen authored
    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>
    1bed74fe
Name
Last commit
Last update
..
commands Loading commit data...
controls Loading commit data...
events Loading commit data...
macosx Loading commit data...
os2 Loading commit data...
parser Loading commit data...
src Loading commit data...
utils Loading commit data...
vars Loading commit data...
win32 Loading commit data...
x11 Loading commit data...
.gitignore Loading commit data...
Modules.am Loading commit data...