diff --git a/ini.cpp b/ini.cpp index 1f1d2f2..4fb4e3a 100644 --- a/ini.cpp +++ b/ini.cpp @@ -114,12 +114,17 @@ int INIClass::Load(Straw& straw) line[0] = ' '; *strchr(line, ']') = '\0'; strtrim(line); - INISection* section = new INISection(newstr(line)); - if (!section) - { - Clear(0, 0); - return false; + + INISection* section; + + try { + section = new INISection(newstr(line)); } + catch (std::bad_alloc& ba) { + Clear(0, 0); + return false; + } + while (!isLastLine) { int count = Read_Line(cacheStraw, line, 512, isLastLine); @@ -146,13 +151,17 @@ int INIClass::Load(Straw& straw) { continue; } - INIEntry* entry = new INIEntry(newstr(key), newstr(value)); - if (!entry) - { - delete section; - Clear(0, 0); - return false; + + INIEntry* entry; + try { + entry = new INIEntry(newstr(key), newstr(value)); } + catch (std::bad_alloc& ba) { + delete section; + Clear(0, 0); + return false; + } + uint32 crc = CRC_String(entry->Entry, 0); if (section->EntryIndex.Is_Present(crc)) DuplicateCRCError(__FUNCTION__, section->Section, line); diff --git a/vector.h b/vector.h index 13cd7ed..c54b08f 100644 --- a/vector.h +++ b/vector.h @@ -1,5 +1,7 @@ #pragma once #include "CriticalSectionClass.h" +#include + template class NoEqualsClass { public: @@ -55,15 +57,16 @@ template class VectorClass { VectorMax = vector.Length(); if (VectorMax) { - Vector = new T[VectorMax]; - if (Vector) - { + try { + Vector = new T[VectorMax]; IsAllocated = true; for (int index = 0; index < VectorMax; index++) { Vector[index] = vector[index]; } } + catch (std::bad_alloc& ba) { + } } else { @@ -1226,11 +1229,12 @@ template class IndexClass { if (amount >= 0) { int newsize = IndexSize + amount; - NodeElement *newindex = new NodeElement[newsize]; - if (newindex) - { + + NodeElement *newindex; + try { + newindex = new NodeElement[newsize]; UL_ASSERT(IndexCount < newsize); - for (int i = 0;i < this->IndexCount;i++) + for (int i = 0; i < this->IndexCount; i++) { newindex[i].ID = IndexTable[i].ID; newindex[i].Data = IndexTable[i].Data; @@ -1242,6 +1246,8 @@ template class IndexClass { Invalidate_Archive(); return true; } + catch (std::bad_alloc& ba) { + } } return false; }