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:
Hugo Beauzée-Luyssen <hugo@beauzee.fr>
Showing
- modules/access/dshow/filter.cpp 7 additions, 4 deletionsmodules/access/dshow/filter.cpp
- modules/access/live555.cpp 2 additions, 1 deletionmodules/access/live555.cpp
- modules/demux/adaptative/mp4/AtomsReader.cpp 2 additions, 1 deletionmodules/demux/adaptative/mp4/AtomsReader.cpp
- modules/demux/mkv/matroska_segment.cpp 5 additions, 3 deletionsmodules/demux/mkv/matroska_segment.cpp
- modules/demux/mkv/mkv.cpp 3 additions, 1 deletionmodules/demux/mkv/mkv.cpp
- modules/demux/mkv/virtual_segment.cpp 2 additions, 1 deletionmodules/demux/mkv/virtual_segment.cpp
- modules/demux/sid.cpp 5 additions, 3 deletionsmodules/demux/sid.cpp
- modules/gui/qt4/dialogs/fingerprintdialog.cpp 2 additions, 1 deletionmodules/gui/qt4/dialogs/fingerprintdialog.cpp
- modules/gui/skins2/commands/async_queue.cpp 2 additions, 1 deletionmodules/gui/skins2/commands/async_queue.cpp
- modules/gui/skins2/src/art_manager.cpp 3 additions, 1 deletionmodules/gui/skins2/src/art_manager.cpp
- modules/gui/skins2/src/var_manager.cpp 2 additions, 2 deletionsmodules/gui/skins2/src/var_manager.cpp
- modules/gui/skins2/x11/x11_window.cpp 3 additions, 1 deletionmodules/gui/skins2/x11/x11_window.cpp
Loading
Please register or sign in to comment