From 0f99c2d712fb94f494c62d2cb507a49eb8ea4414 Mon Sep 17 00:00:00 2001 From: Denis Charmet Date: Fri, 26 Apr 2013 23:34:40 +0200 Subject: [PATCH] Use (std::nothrow) with new when the code check for null pointer results. --- src/EbmlCrc32.cpp | 4 ++-- src/EbmlElement.cpp | 6 ++++-- src/EbmlString.cpp | 4 ++-- src/EbmlUnicodeString.cpp | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/EbmlCrc32.cpp b/src/EbmlCrc32.cpp index 850c859..77b5982 100644 --- a/src/EbmlCrc32.cpp +++ b/src/EbmlCrc32.cpp @@ -217,7 +217,7 @@ filepos_t EbmlCrc32::RenderData(IOCallback & output, bool /* bForceRender */, bo if (Result < GetDefaultSize()) { // pad the rest with 0 - binary *Pad = new binary[GetDefaultSize() - Result]; + binary *Pad = new (std::nothrow) binary[GetDefaultSize() - Result]; if (Pad != NULL) { memset(Pad, 0x00, GetDefaultSize() - Result); output.writeFully(Pad, GetDefaultSize() - Result); @@ -234,7 +234,7 @@ filepos_t EbmlCrc32::ReadData(IOCallback & input, ScopeMode ReadFully) { if (ReadFully != SCOPE_NO_DATA) { - binary *Buffer = new binary[GetSize()]; + binary *Buffer = new (std::nothrow) binary[GetSize()]; if (Buffer == NULL) { // impossible to read, skip it input.setFilePointer(GetSize(), seek_current); diff --git a/src/EbmlElement.cpp b/src/EbmlElement.cpp index 4b96d06..c503088 100644 --- a/src/EbmlElement.cpp +++ b/src/EbmlElement.cpp @@ -317,7 +317,9 @@ EbmlElement * EbmlElement::FindNextID(IOCallback & DataStream, const EbmlCallbac Result = &EBML_INFO_CREATE(ClassInfos); } else { /// \todo find the element in the context - Result = new EbmlDummy(PossibleID); + Result = new (std::nothrow) EbmlDummy(PossibleID); + if(Result == NULL) + return NULL; } Result->SetSizeLength(PossibleSizeLength); @@ -565,7 +567,7 @@ EbmlElement *EbmlElement::CreateElementUsingContext(const EbmlId & aID, const Eb if (!IsGlobalContext && bAllowDummy) { LowLevel = 0; - Result = new EbmlDummy(aID); + Result = new (std::nothrow) EbmlDummy(aID); } return Result; diff --git a/src/EbmlString.cpp b/src/EbmlString.cpp index 5341ec0..7f8ee2c 100644 --- a/src/EbmlString.cpp +++ b/src/EbmlString.cpp @@ -95,7 +95,7 @@ filepos_t EbmlString::RenderData(IOCallback & output, bool /* bForceRender */, b if (Result < GetDefaultSize()) { // pad the rest with 0 - binary *Pad = new binary[GetDefaultSize() - Result]; + binary *Pad = new (std::nothrow) binary[GetDefaultSize() - Result]; if (Pad == NULL) { return Result; @@ -151,7 +151,7 @@ filepos_t EbmlString::ReadData(IOCallback & input, ScopeMode ReadFully) Value = ""; SetValueIsSet(); } else { - char *Buffer = new char[GetSize() + 1]; + char *Buffer = new (std::nothrow) char[GetSize() + 1]; if (Buffer == NULL) { // unable to store the data, skip it input.setFilePointer(GetSize(), seek_current); diff --git a/src/EbmlUnicodeString.cpp b/src/EbmlUnicodeString.cpp index 56c5606..0b0857d 100644 --- a/src/EbmlUnicodeString.cpp +++ b/src/EbmlUnicodeString.cpp @@ -273,7 +273,7 @@ filepos_t EbmlUnicodeString::RenderData(IOCallback & output, bool /* bForceRende if (Result < GetDefaultSize()) { // pad the rest with 0 - binary *Pad = new binary[GetDefaultSize() - Result]; + binary *Pad = new (std::nothrow) binary[GetDefaultSize() - Result]; if (Pad != NULL) { memset(Pad, 0x00, GetDefaultSize() - Result); output.writeFully(Pad, GetDefaultSize() - Result); @@ -339,7 +339,7 @@ filepos_t EbmlUnicodeString::ReadData(IOCallback & input, ScopeMode ReadFully) Value = UTFstring::value_type(0); SetValueIsSet(); } else { - char *Buffer = new char[GetSize()+1]; + char *Buffer = new (std::nothrow) char[GetSize()+1]; if (Buffer == NULL) { // impossible to read, skip it input.setFilePointer(GetSize(), seek_current);