Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ren MALLOC to malloc, fix malloc overflow on large sizes
- Loading branch information
1 parent
c7638f7
commit 1ba0e41
Showing
2 changed files
with
41 additions
and
25 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* Copyright (C) 1986-1994 by Digital Mars. $Revision: 1.1.1.1 $ */ | ||
|
||
#include <stdlib.h> | ||
#include "semlock.h" | ||
#include "multpool.h" | ||
|
||
#if __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
void *malloc (size_t m_size) | ||
{ | ||
#if USEHEAP | ||
/* The +2 is because there's a buffer overflow somewhere in stlport. | ||
* It is triggered by stltutorial\ex13-01.cpp | ||
*/ | ||
#if _WIN32 | ||
/* Set a max size because of access violations in Win32 Heap functions. | ||
* Size is determined experimentally. | ||
*/ | ||
if (m_size < 0xD5550000) | ||
return HeapAlloc(_default_heap, 0, m_size + 2); | ||
return NULL; | ||
#else | ||
return HeapAlloc(_default_heap, 0, m_size + 2); | ||
#endif | ||
#else | ||
void *p; | ||
|
||
LockSemaphore(_semAlloc); | ||
p = RTLMultiPool::GetMainHeap()->Alloc(m_size); | ||
UnlockSemaphore(_semAlloc); | ||
|
||
return p; | ||
#endif | ||
} | ||
|
||
#if __cplusplus | ||
} | ||
#endif | ||
|