Mail Archives: djgpp-workers/2001/07/04/05:04:29
On Tue, 3 Jul 2001, I wrote:
> If that doesn't work, I think we can safely decline anything above 2GB,
> which will avoid the signed/unsigned nuisance (inside malloc as well).
Does the following look right?
--- malloc.c~0 Wed Jul 4 09:55:04 2001
+++ malloc.c Wed Jul 4 11:10:02 2001
@@ -132,6 +132,16 @@ malloc(size_t size)
if (size<ALIGN) size = ALIGN;
size = (size+(ALIGN-1))&~(ALIGN-1);
+
+ /* Refuse ridiculously large requests right away. Anything beyond
+ 2GB will be treated by sbrk as a negative request, i.e. as a
+ request to _decrease_ the heap size. */
+ if (size > 0x7fffffff - 0x10000) /* sbrk rounds up to 64KB */
+ {
+ if (__libc_malloc_fail_hook)
+ __libc_malloc_fail_hook(size);
+ return 0;
+ }
#if DEBUG
printf("malloc(%u)\n", size);
#endif
- Raw text -