• 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
sid.cpp 8.06 KB