bug-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Windows realloc & GNU


From: Conrad T. Pino
Subject: RE: Windows realloc & GNU
Date: Tue, 20 Sep 2005 13:13:32 -0700

> From: Derek Price
> Sent: Tuesday, September 20, 2005 12:44
> 
> Then you should be okay, though a few additional tests may be in order
> just to be sure (does the pointer look like it is from the same general
> data space as a pointer returned from malloc(1) in the same program? 
> can you write a single byte to it without memory protection catching a
> fault?  Can you free it without a fault?)

Yes.

Yes but the "free" function detects the write past the end and displays
a dialog box with "Abort", "Retry", "Ignore" options.  Nothing odd occurs
when "free" isn't called.  Looks clean to me.

Yes.

This code:

#include <stdio.h>
#include <malloc.h>

int main(int argc, char* argv[])
{
        char *pm, *pr;

        printf("Hello World!\n");
        printf("argv = %p\n", argv);
        printf("\n");

        pm = malloc( 0 );
        pr = realloc( 0, 0 );

        printf("malloc( 0 ) = %p\n", pm);
        printf("realloc( 0, 0 ) = %p\n", pr);
        printf("*realloc( 0, 0 ) = 0x%02X\n", *pr);
        printf("*realloc( 0, 0 ) = 2\n");
        *pr = 2;
        printf("*realloc( 0, 0 ) = 0x%02X\n", *pr);
        printf("\n");

        free(pm); pm = NULL;
        free(pr); pr = NULL;

        pm = malloc( 1 );
        pr = realloc( 0, 0 );

        printf("malloc( 1 ) = %p\n", pm);
        printf("realloc( 0, 0 ) = %p\n", pr);
        printf("*realloc( 0, 0 ) = 0x%02X\n", *pr);
        printf("*realloc( 0, 0 ) = 3\n");
        *pr = 3;
        printf("*realloc( 0, 0 ) = 0x%02X\n", *pr);
        printf("\n");

        free(pm); pm = NULL;
        free(pr); pr = NULL;

        return 0;
}

Does this:

Hello World!
argv = 002F0EE0

malloc( 0 ) = 002F07A8
realloc( 0, 0 ) = 002F07E0
*realloc( 0, 0 ) = 0xFFFFFFFD
*realloc( 0, 0 ) = 2
*realloc( 0, 0 ) = 0x02

malloc( 1 ) = 002F07A8
realloc( 0, 0 ) = 002F07E0
*realloc( 0, 0 ) = 0xFFFFFFFD
*realloc( 0, 0 ) = 3
*realloc( 0, 0 ) = 0x03





reply via email to

[Prev in Thread] Current Thread [Next in Thread]