Use size_t instead of int in the memory allocation routines

size_t is the correct type to use when specifying the memory-size of an
object. That is why sizeof(), strlen() and malloc() all use it.
pull/3/head
Daniel Richard G 2013-08-26 16:40:25 -04:00
parent dcc963aa4b
commit 1b00c8c3ab
2 changed files with 6 additions and 6 deletions

View File

@ -167,11 +167,11 @@ void CnfThawString(char *str, int maxLen, const char *name);
DWORD CnfThawDWORD(DWORD v, const char *name); DWORD CnfThawDWORD(DWORD v, const char *name);
float CnfThawFloat(float v, const char *name); float CnfThawFloat(float v, const char *name);
void *AllocTemporary(int n); void *AllocTemporary(size_t n);
void FreeTemporary(void *p); void FreeTemporary(void *p);
void FreeAllTemporary(void); void FreeAllTemporary(void);
void *MemRealloc(void *p, int n); void *MemRealloc(void *p, size_t n);
void *MemAlloc(int n); void *MemAlloc(size_t n);
void MemFree(void *p); void MemFree(void *p);
void InitHeaps(void); void InitHeaps(void);
void vl(void); // debug function to validate heaps void vl(void); // debug function to validate heaps

View File

@ -39,7 +39,7 @@ void GetAbsoluteFilename(char *file)
// to be sloppy with our memory management, and just free everything at once // to be sloppy with our memory management, and just free everything at once
// at the end. // at the end.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void *AllocTemporary(int n) void *AllocTemporary(size_t n)
{ {
void *v = HeapAlloc(TempHeap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, n); void *v = HeapAlloc(TempHeap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, n);
if(!v) oops(); if(!v) oops();
@ -57,7 +57,7 @@ void FreeAllTemporary(void)
vl(); vl();
} }
void *MemRealloc(void *p, int n) { void *MemRealloc(void *p, size_t n) {
if(!p) { if(!p) {
return MemAlloc(n); return MemAlloc(n);
} }
@ -66,7 +66,7 @@ void *MemRealloc(void *p, int n) {
if(!p) oops(); if(!p) oops();
return p; return p;
} }
void *MemAlloc(int n) { void *MemAlloc(size_t n) {
void *p = HeapAlloc(PermHeap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, n); void *p = HeapAlloc(PermHeap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, n);
if(!p) oops(); if(!p) oops();
return p; return p;