diff options
| author | Joel de Vahl <joel@stalverk80.se> | 2008-10-06 16:44:34 +0000 |
|---|---|---|
| committer | Joel de Vahl <joel@stalverk80.se> | 2008-10-06 16:44:34 +0000 |
| commit | d1b55351ccc2252917ad494b74bb6ad562df34ce (patch) | |
| tree | c797ff1df77593bd8d36ddf41c235f65a5508b30 /src/base | |
| parent | 78d129c0519166f8ab2e84acbccc3f604ed70b0b (diff) | |
| download | zcatch-d1b55351ccc2252917ad494b74bb6ad562df34ce.tar.gz zcatch-d1b55351ccc2252917ad494b74bb6ad562df34ce.zip | |
Big endian fix.
Diffstat (limited to 'src/base')
| -rw-r--r-- | src/base/system.c | 22 | ||||
| -rw-r--r-- | src/base/system.h | 7 |
2 files changed, 27 insertions, 2 deletions
diff --git a/src/base/system.c b/src/base/system.c index 02bbed7f..88b73f32 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -156,6 +156,7 @@ typedef struct MEMTAIL } MEMTAIL; static struct MEMHEADER *first = 0; +static const int MEM_GUARD_VAL = 0xbaadc0de; void *mem_alloc_debug(const char *filename, int line, unsigned size, unsigned alignment) { @@ -171,7 +172,7 @@ void *mem_alloc_debug(const char *filename, int line, unsigned size, unsigned al memory_stats.total_allocations++; memory_stats.active_allocations++; - tail->guard = 0xbaadc0de; + tail->guard = MEM_GUARD_VAL; header->prev = (MEMHEADER *)0; header->next = first; @@ -190,7 +191,7 @@ void mem_free(void *p) MEMHEADER *header = (MEMHEADER *)p - 1; MEMTAIL *tail = (MEMTAIL *)(((char*)(header+1))+header->size); - if(tail->guard != 0xbaadc0de) + if(tail->guard != MEM_GUARD_VAL) dbg_msg("mem", "!! %p", p); /* dbg_msg("mem", "-- %p", p); */ memory_stats.allocated -= header->size; @@ -239,6 +240,21 @@ void mem_zero(void *block,unsigned size) memset(block, 0, size); } +void mem_check() +{ + MEMHEADER *header = first; + while(header) + { + MEMTAIL *tail = (MEMTAIL *)(((char*)(header+1))+header->size); + if(tail->guard != MEM_GUARD_VAL) + { + dbg_msg("mem", "Memory check failed at %s(%d): %d", header->filename, header->line, header->size); + dbg_assert(0, "Memory check failed"); + } + header = header->next; + } +} + IOHANDLE io_open(const char *filename, int flags) { if(flags == IOFLAG_READ) @@ -876,7 +892,9 @@ int fs_storage_path(const char *appname, char *path, int max) return 0; #else char *home = getenv("HOME"); +#if !defined(CONF_PLATFORM_MACOSX) int i; +#endif if(!home) return -1; diff --git a/src/base/system.h b/src/base/system.h index e7c3586f..36f370cd 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -161,6 +161,13 @@ void mem_zero(void *block, unsigned size); */ int mem_comp(const void *a, const void *b, int size); +/* + Function: mem_check + Validates the heap + Will trigger a assert if memory has failed. +*/ +void mem_check(); + /* Group: File IO */ enum { IOFLAG_READ = 1, |