From: Daniel Barker Newsgroups: comp.os.msdos.djgpp Subject: malloc() problem, DJDEV 203 Date: Mon, 2 Jul 2001 22:55:15 +0100 Organization: Edinburgh University Lines: 32 Message-ID: NNTP-Posting-Host: holyrood.ed.ac.uk Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: scotsman.ed.ac.uk 994110915 20037 129.215.16.14 (2 Jul 2001 21:55:15 GMT) X-Complaints-To: usenet AT scotsman DOT ed DOT ac DOT uk NNTP-Posting-Date: 2 Jul 2001 21:55:15 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Unless I have been staring at the screen too long, there is a bug in DJGPP malloc(). malloc() does not indicate failure when a very large allocation is attempted. I noticed this whilst checking a test I have written for my own malloc() wrapper function. malloc() does not indicate failure for a very large allocation. Here's a small example, tested with DJDEV 203 and gcc2952. c:/My\ Documents $ cat mallocbug.c /* mallocbug.c */ #include #include int main(void) { char *p = malloc((size_t) -1); printf("NULL = %p\n", (void *) NULL); printf("p = %p\n", (void *) p); return 0; } c:/My\ Documents $ gcc -ansi -o mallocbug.exe mallocbug.c c:/My\ Documents $ ./mallocbug.exe NULL = 0 p = 8fae8 -- Daniel Barker.