[vlc-commits] nothrow new in cases where it maches intent
Filip Roséen
git at videolan.org
Wed Feb 17 13:05:27 CET 2016
vlc | branch: master | Filip Roséen <filip at atch.se> | Wed Feb 17 12:16:31 2016 +0100| [1bed74fe7b32622b1aa39d08516467b72a21e71d] | committer: Hugo Beauzée-Luyssen
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 at beauzee.fr>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1bed74fe7b32622b1aa39d08516467b72a21e71d
---
modules/access/dshow/filter.cpp | 11 +++++++----
modules/access/live555.cpp | 3 ++-
modules/demux/adaptative/mp4/AtomsReader.cpp | 3 ++-
modules/demux/mkv/matroska_segment.cpp | 8 +++++---
modules/demux/mkv/mkv.cpp | 4 +++-
modules/demux/mkv/virtual_segment.cpp | 3 ++-
modules/demux/sid.cpp | 8 +++++---
modules/gui/qt4/dialogs/fingerprintdialog.cpp | 3 ++-
modules/gui/skins2/commands/async_queue.cpp | 3 ++-
modules/gui/skins2/src/art_manager.cpp | 4 +++-
modules/gui/skins2/src/var_manager.cpp | 4 ++--
modules/gui/skins2/x11/x11_window.cpp | 4 +++-
12 files changed, 38 insertions(+), 20 deletions(-)
Diff: http://git.videolan.org/gitweb.cgi/vlc.git/?a=commitdiff;h=1bed74fe7b32622b1aa39d08516467b72a21e71d
More information about the vlc-commits
mailing list