aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config-file.cpp28
-rw-r--r--main.cpp2
-rw-r--r--resource.cpp36
-rw-r--r--scumm.h3
-rw-r--r--sound.cpp4
-rw-r--r--sys.cpp41
-rw-r--r--v3/resource_v3.cpp2
7 files changed, 37 insertions, 79 deletions
diff --git a/config-file.cpp b/config-file.cpp
index ccb4816e77..36af37eb1d 100644
--- a/config-file.cpp
+++ b/config-file.cpp
@@ -72,7 +72,7 @@ keys(0), values(0), nkeys(0)
hashconfig::~hashconfig()
{
- Scumm::free(domain);
+ free(domain);
}
bool hashconfig::is_domain(const char *d) const
@@ -99,14 +99,14 @@ const char *hashconfig::set(const char *key, const char *value)
for (i = 0; i < nkeys; i++) {
if (!strcmp(key, keys[i])) {
- Scumm::free(values[i]);
+ free(values[i]);
return values[i] = value ? Scumm::Strdup(value) : 0;
}
}
nkeys++;
- keys = (char **)Scumm::realloc(keys, nkeys * sizeof(char *));
- values = (char **)Scumm::realloc(values, nkeys * sizeof(char *));
+ keys = (char **)realloc(keys, nkeys * sizeof(char *));
+ values = (char **)realloc(values, nkeys * sizeof(char *));
keys[nkeys - 1] = Scumm::Strdup(key);
return values[nkeys - 1] = value ? Scumm::Strdup(value) : 0;
}
@@ -135,7 +135,7 @@ void hashconfig::flush(FILE * cfg_file) const
void hashconfig::rename(const char *d)
{
- Scumm::free(domain);
+ free(domain);
domain = d ? Scumm::Strdup(d) : 0;
}
@@ -208,13 +208,13 @@ Config::~Config()
{
int i;
- Scumm::free(filename);
- Scumm::free(domain);
+ free(filename);
+ free(domain);
for (i = 0; i < ndomains; i++) {
delete hash[i];
}
- Scumm::free(hash);
+ free(hash);
}
const char *Config::get(const char *key, const char *d) const
@@ -248,7 +248,7 @@ const char *Config::set(const char *key, const char *value, const char *d)
ndomains++;
hash =
- (hashconfig **) Scumm::realloc(hash, ndomains * sizeof(hashconfig *));
+ (hashconfig **) realloc(hash, ndomains * sizeof(hashconfig *));
hash[ndomains - 1] = new hashconfig(domain);
return hash[ndomains - 1]->set(key, value);
@@ -272,7 +272,7 @@ const char *Config::set(const char *key, int value_i, const char *d)
ndomains++;
hash =
- (hashconfig **) Scumm::realloc(hash, ndomains * sizeof(hashconfig *));
+ (hashconfig **) realloc(hash, ndomains * sizeof(hashconfig *));
hash[ndomains - 1] = new hashconfig(domain);
return hash[ndomains - 1]->set(key, value);
@@ -281,7 +281,7 @@ const char *Config::set(const char *key, int value_i, const char *d)
void Config::set_domain(const char *d)
{
int i;
- Scumm::free(domain);
+ free(domain);
domain = d ? Scumm::Strdup(d) : 0;
for (i = 0; i < ndomains; i++) {
@@ -290,7 +290,7 @@ void Config::set_domain(const char *d)
}
ndomains++;
hash =
- (hashconfig **) Scumm::realloc(hash, ndomains * sizeof(hashconfig *));
+ (hashconfig **) realloc(hash, ndomains * sizeof(hashconfig *));
hash[ndomains - 1] = new hashconfig(domain);
}
@@ -346,7 +346,7 @@ void Config::delete_domain(const char *d)
void Config::change_filename(const char *f)
{
- Scumm::free(filename);
+ free(filename);
filename = f ? Scumm::Strdup(f) : 0;
}
@@ -367,7 +367,7 @@ void Config::merge_config(const Config * c)
if (!found) {
ndomains++;
hash =
- (hashconfig **) Scumm::realloc(hash, ndomains * sizeof(hashconfig *));
+ (hashconfig **) realloc(hash, ndomains * sizeof(hashconfig *));
hash[ndomains - 1] = new hashconfig(domain);
hash[ndomains - 1]->merge(c->hash[i]);
}
diff --git a/main.cpp b/main.cpp
index f4916f51c7..08adf90178 100644
--- a/main.cpp
+++ b/main.cpp
@@ -107,7 +107,7 @@ int main(int argc, char *argv[])
{
char *s = detector.getGameName();
system->property(OSystem::PROP_SET_WINDOW_CAPTION, (long)s);
- Scumm::free(s);
+ free(s);
}
/* Simon the Sorcerer? */
diff --git a/resource.cpp b/resource.cpp
index a92f003787..1a50cf684f 100644
--- a/resource.cpp
+++ b/resource.cpp
@@ -403,12 +403,12 @@ void Scumm::allocResTypeData(int id, uint32 tag, int num, const char *name,
res.num[id] = num;
res.tags[id] = tag;
res.name[id] = name;
- res.address[id] = (byte **)alloc(num * sizeof(void *));
- res.flags[id] = (byte *)alloc(num * sizeof(byte));
+ res.address[id] = (byte **)calloc(num, sizeof(void *));
+ res.flags[id] = (byte *)calloc(num, sizeof(byte));
if (mode) {
- res.roomno[id] = (byte *)alloc(num * sizeof(byte));
- res.roomoffs[id] = (uint32 *)alloc(num * sizeof(uint32));
+ res.roomno[id] = (byte *)calloc(num, sizeof(byte));
+ res.roomoffs[id] = (uint32 *)calloc(num, sizeof(uint32));
}
}
@@ -750,7 +750,7 @@ byte *Scumm::createResource(int type, int idx, uint32 size)
expireResources(size);
- CHECK_HEAP ptr = (byte *)alloc(size + sizeof(MemBlkHeader) + SAFETY_AREA);
+ CHECK_HEAP ptr = (byte *)calloc(size + sizeof(MemBlkHeader) + SAFETY_AREA, 1);
if (ptr == NULL) {
error("Out of memory while allocating %d", size);
}
@@ -1133,7 +1133,7 @@ void Scumm::readMAXS()
_numCharsets = fileReadWordLE();
_numCostumes = fileReadWordLE();
- _objectRoomTable = (byte *)alloc(_numGlobalObjects);
+ _objectRoomTable = (byte *)calloc(_numGlobalObjects, 1);
_numGlobalScripts = 2000;
_shadowPaletteSize = NUM_SHADOW_PALETTE * 256;
@@ -1182,7 +1182,7 @@ void Scumm::readMAXS()
}
if (_shadowPaletteSize)
- _shadowPalette = (byte *)alloc(_shadowPaletteSize);
+ _shadowPalette = (byte *)calloc(_shadowPaletteSize, 1);
allocateArrays();
_dynamicRoomOffsets = 1;
@@ -1193,17 +1193,17 @@ void Scumm::allocateArrays()
// Note: Buffers are now allocated in scummMain to allow for
// early GUI init.
- _objectOwnerTable = (byte *)alloc(_numGlobalObjects);
- _objectStateTable = (byte *)alloc(_numGlobalObjects);
- _classData = (uint32 *)alloc(_numGlobalObjects * sizeof(uint32));
- _arrays = (byte *)alloc(_numArray);
- _newNames = (uint16 *)alloc(_numNewNames * sizeof(uint16));
-
- _inventory = (uint16 *)alloc(_numInventory * sizeof(uint16));
- _verbs = (VerbSlot *)alloc(_numVerbs * sizeof(VerbSlot));
- _objs = (ObjectData *)alloc(_numLocalObjects * sizeof(ObjectData));
- _vars = (int16 *) alloc(_numVariables * sizeof(int16));
- _bitVars = (byte *)alloc(_numBitVariables >> 3);
+ _objectOwnerTable = (byte *)calloc(_numGlobalObjects, 1);
+ _objectStateTable = (byte *)calloc(_numGlobalObjects, 1);
+ _classData = (uint32 *)calloc(_numGlobalObjects, sizeof(uint32));
+ _arrays = (byte *)calloc(_numArray, 1);
+ _newNames = (uint16 *)calloc(_numNewNames, sizeof(uint16));
+
+ _inventory = (uint16 *)calloc(_numInventory, sizeof(uint16));
+ _verbs = (VerbSlot *)calloc(_numVerbs, sizeof(VerbSlot));
+ _objs = (ObjectData *)calloc(_numLocalObjects, sizeof(ObjectData));
+ _vars = (int16 *) calloc(_numVariables, sizeof(int16));
+ _bitVars = (byte *)calloc(_numBitVariables >> 3, 1);
allocResTypeData(rtCostume,
(_features & GF_NEW_COSTUMES) ? MKID('AKOS') :
diff --git a/scumm.h b/scumm.h
index ca4d80f863..2bc475e81b 100644
--- a/scumm.h
+++ b/scumm.h
@@ -1351,9 +1351,6 @@ public:
uint fileReadWordLE(void *handle);
uint fileReadWordBE(void *handle);
- static byte *alloc(int size);
- static byte *realloc(void *mem, int size);
- static void free(void *mem);
static char *Strdup(const char *);
/* Version 5 script opcodes */
diff --git a/sound.cpp b/sound.cpp
index ab6336b5cc..491350df32 100644
--- a/sound.cpp
+++ b/sound.cpp
@@ -711,8 +711,8 @@ void Scumm::decompressBundleSound(int index) {
unsigned char *p;
fileSeek(_sfxFile, bundle_table[index].offset + table[i].offset, SEEK_SET);
- CompInput = (unsigned char *)alloc(table[i].size);
- CompOutput = (unsigned char *)alloc(10000);
+ CompInput = (unsigned char *)malloc(table[i].size);
+ CompOutput = (unsigned char *)malloc(10000);
fileRead((FILE *)_sfxFile, CompInput, table[i].size);
diff --git a/sys.cpp b/sys.cpp
index 7ac1db91d6..e7b5437bba 100644
--- a/sys.cpp
+++ b/sys.cpp
@@ -201,50 +201,11 @@ uint32 Scumm::fileReadDwordBE(void *handle)
return (b << 16) | a;
}
-byte *Scumm::alloc(int size)
-{
- byte *me = (byte *)::calloc(size + 4, 1);
- if (me == NULL)
- return NULL;
-
- *((uint32 *)me) = 0xDEADBEEF;
- return me + 4;
-}
-
-void Scumm::free(void *mem)
-{
- if (mem) {
- byte *me = (byte *)mem - 4;
- if (*((uint32 *)me) != 0xDEADBEEF) {
- error("Freeing invalid block.");
- }
-
- *((uint32 *)me) = 0xC007CAFE;
- ::free(me);
- }
-}
-
-byte *Scumm::realloc(void *mem, int size)
-{
- byte * me = (byte *) mem;
- if (mem) {
- if (size) {
- me = (byte *) ::realloc((me - 4), size + 4);
- return me + 4;
- } else {
- free(me);
- return NULL;
- }
- } else {
- return alloc(size);
- }
-}
-
char *Scumm::Strdup(const char *s)
{
if (s) {
int l = strlen(s) + 1;
- char * r = (char *) alloc(l);
+ char * r = (char *) malloc(l);
memcpy(r, s, l);
return r;
}
diff --git a/v3/resource_v3.cpp b/v3/resource_v3.cpp
index c4ea3e7296..18e8002d94 100644
--- a/v3/resource_v3.cpp
+++ b/v3/resource_v3.cpp
@@ -82,7 +82,7 @@ void Scumm_v3::readIndexFile()
_numGlobalScripts = 200;
_shadowPaletteSize = 256;
- _shadowPalette = (byte *)alloc(_shadowPaletteSize); // stupid for now. Need to be removed later
+ _shadowPalette = (byte *)calloc(_shadowPaletteSize, 1); // stupid for now. Need to be removed later
_numFlObject = 50;
allocateArrays();