Article View: comp.os.os2.programmer
Article #2227Re: malloc (...) in gcc+emx
From: 873clifton
Date: Fri, 02 Oct 1992 01:43
Date: Fri, 02 Oct 1992 01:43
37 lines
1612 bytes
1612 bytes
In article <1992Sep30.173840.17721@Informatik.TU-Muenchen.DE>, maehner@Informatik.TU-Muenchen.DE (Johannes Maehner) writes:
>
> I've got the gcc2.2.2+emx0.8e programming environment for OS/2 2.0.
> Consider the following C-program:
>
> #include <stdio.h>
> #include <malloc.h>
>
> void main ()
> {
> char *buf = (char *) malloc (<size>);
>
> if (buf != NULL) printf ("memory allocated\n");
> else printf ("allocation failed\n");
> free (buf);
> }
>
> The behavior of the program:
> If <size> gets too high (of course, <size>
> is in a valid integer range and >= 0) malloc doesn't return a
> NULL - pointer but the program turns in a core-dump
> (gdb says that the program received signal 11, segmentation-fault)
>
> Can YOU tell me how to solve the problem?
> (I guess malloc gets in conflict with the
> memory protection of OS/2 2.0 but doesn't recognize
> it as an error)
> Is there a way to use the virtual memory management
> when allocating store on the heap?
>
Try replacing a straight integer value for <size> with: sizeof(char)*SIZE
where SIZE is the integer you where using previously.
/Doug
--
Douglas Clifton [99clifto@lab.cc.wmich.edu]
Technical Details
Message-ID:
<1992Oct1.204338.5591@gw.wmich.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!usc!wupost!gumby!wmichgw!873cliftonReferences:
<1992Sep30.173840.17721@Informatik.TU-Muenchen.DE>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!wupost!gumby!wmichgw!873clifton From: 873clifton@gw.wmich.edu Newsgroups: comp.os.os2.programmer Subject: Re: malloc (...) in gcc+emx Message-ID: <1992Oct1.204338.5591@gw.wmich.edu> Date: 1 Oct 92 20:43:38 EST References: <1992Sep30.173840.17721@Informatik.TU-Muenchen.DE> Organization: Western Michigan University Lines: 37