www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/07/02/18:00:18

From: Daniel Barker <sokal AT holyrood DOT ed DOT ac DOT uk>
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: <Pine.SOL.4.33.0107022250120.27631-100000@holyrood.ed.ac.uk>
NNTP-Posting-Host: holyrood.ed.ac.uk
Mime-Version: 1.0
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 <stdio.h>
#include <stdlib.h>

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.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019