diff options
author | Travis Howell | 2007-07-25 11:29:47 +0000 |
---|---|---|
committer | Travis Howell | 2007-07-25 11:29:47 +0000 |
commit | cf3719d613a0947ce46b5541e378532b4cbcf394 (patch) | |
tree | 1424cd8a7e1b8111c928a1366b6ec679da60acab /engines/agos | |
parent | 5c588e1f5e4b80fb345f14a3a2cafcf8c6fdc352 (diff) | |
download | scummvm-rg350-cf3719d613a0947ce46b5541e378532b4cbcf394.tar.gz scummvm-rg350-cf3719d613a0947ce46b5541e378532b4cbcf394.tar.bz2 scummvm-rg350-cf3719d613a0947ce46b5541e378532b4cbcf394.zip |
Add eriktorbjorn's patch for bug #1498158 - AOGS: Itemheap overflow on 64bit systems.
svn-id: r28189
Diffstat (limited to 'engines/agos')
-rw-r--r-- | engines/agos/agos.cpp | 16 | ||||
-rw-r--r-- | engines/agos/agos.h | 5 | ||||
-rw-r--r-- | engines/agos/items.cpp | 19 |
3 files changed, 17 insertions, 23 deletions
diff --git a/engines/agos/agos.cpp b/engines/agos/agos.cpp index ae7f692c3f..ba429b510c 100644 --- a/engines/agos/agos.cpp +++ b/engines/agos/agos.cpp @@ -148,10 +148,6 @@ AGOSEngine::AGOSEngine(OSystem *syst) _itemArraySize = 0; _itemArrayInited = 0; - _itemHeapPtr = 0; - _itemHeapCurPos = 0; - _itemHeapSize = 0; - _iconFilePtr = 0; _codePtr = 0; @@ -920,7 +916,11 @@ AGOSEngine::~AGOSEngine() { _midi.close(); - free(_itemHeapPtr - _itemHeapCurPos); + for (uint i = 0; i < _itemHeap.size(); i++) { + delete [] _itemHeap[i]; + } + _itemHeap.clear(); + free(_tablesHeapPtr - _tablesHeapCurPos); free(_gameOffsetsPtr); @@ -1054,7 +1054,11 @@ void AGOSEngine::shutdown() { _midi.close(); - free(_itemHeapPtr - _itemHeapCurPos); + for (uint i = 0; i < _itemHeap.size(); i++) { + delete [] _itemHeap[i]; + } + _itemHeap.clear(); + free(_tablesHeapPtr - _tablesHeapCurPos); free(_gameOffsetsPtr); diff --git a/engines/agos/agos.h b/engines/agos/agos.h index d233d0bfeb..bf64a3bf84 100644 --- a/engines/agos/agos.h +++ b/engines/agos/agos.h @@ -28,6 +28,7 @@ #include "engines/engine.h" +#include "common/array.h" #include "common/keyboard.h" #include "common/rect.h" #include "common/util.h" @@ -231,9 +232,7 @@ protected: uint _itemArraySize; uint _itemArrayInited; - byte *_itemHeapPtr; - uint _itemHeapCurPos; - uint _itemHeapSize; + Common::Array<byte *> _itemHeap; byte *_iconFilePtr; diff --git a/engines/agos/items.cpp b/engines/agos/items.cpp index 9a46b6e8ac..13034b74c9 100644 --- a/engines/agos/items.cpp +++ b/engines/agos/items.cpp @@ -42,24 +42,15 @@ Child *AGOSEngine::allocateChildBlock(Item *i, uint type, uint size) { } byte *AGOSEngine::allocateItem(uint size) { - byte *org = _itemHeapPtr; - size = (size + sizeof(void*) - 1) & ~(sizeof(void*) - 1); + byte *item = new byte[size]; - _itemHeapPtr += size; - _itemHeapCurPos += size; - - if (_itemHeapCurPos > _itemHeapSize) - error("allocateItem: Itemheap overflow"); - - return org; + memset(item, 0, size); + _itemHeap.push_back(item); + return item; } void AGOSEngine::allocItemHeap() { - _itemHeapSize = _itemMemSize; - _itemHeapCurPos = 0; - _itemHeapPtr = (byte *)calloc(_itemMemSize, 1); - if (!_itemHeapPtr) - error("Out Of Memory - Items"); + _itemHeap.clear(); } bool AGOSEngine::hasIcon(Item *item) { |