Subject: Re: malloc problem
To: None <>
From: Giles Lean <>
List: tech-userlevel
Date: 11/17/2001 08:51:30
> The following program crashes on NetBSD/i386-1.5.2. I expected malloc() to
> return NULL and setting errno to ENOMEM instead of getting a crash. Is there
> any explanation for this, or is it a bug?


On NetBSD/1.5.1 this malloc() succeeds if there is sufficient memory
or fails correctly setting errno to ENOMEM as required.  If this
doesn't work on 1.5.2 then there's an introduced problem, it would
seem.  Can someone else verify on 1.5.2?



#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

main(int argc, char *argv[])
    int m = 0xbfbfdc50;
    char *borkenbuf;

    fprintf(stderr, "m = 0x%x\n", m);
    fprintf(stderr, "I'm still alive\n");
    borkenbuf = malloc(m);
    if (borkenbuf == 0)
        fprintf(stderr, "error return: errno == %d\n", errno);
        fprintf(stderr, "malloc succeeded\n");

    return 0;