[Top][All Lists]

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

Analysis: "rpl_realloc" & Visual C++ 6.0 function "realloc"

From: Conrad T. Pino
Subject: Analysis: "rpl_realloc" & Visual C++ 6.0 function "realloc"
Date: Wed, 7 Apr 2004 11:17:56 -0700

Hi Derek,
I'm looking into subject functions to determine
what value we're getting by using "rpl_realloc"
in the Windows build.
Conclusion qualified by OS and compiler:

On Windows 2000 Visual C++ 6.0 the native "realloc"
conforms to requirements.  The use of "rpl_realloc"
results in negative impact to the project since
Windows build has warnings due to lack of function
Analysis and supporting evidence follows:
Function "rpl_realloc" in lib/realloc.c is simple:

void *
rpl_realloc (void *p, size_t n)
  if (n == 0)
    n = 1;
  if (p == 0)
    return malloc (n);
  return realloc (p, n);

I see the "rpl_realloc" goal as always allocate i.e.
never return "NULL" since "n" is never allowed to be
zero and "p" is ignored if NULL.
I coded a program to test the native "realloc" for
the behavior implemented by "rpl_realloc":

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

#define FREE(arg) if (arg) free(arg), arg=NULL

int main(int argc, char* argv[])
        void *buffer;

        printf("Hello World!\n");

        buffer = realloc( NULL, 0 );
        printf( "case NULL,0: %p\n", buffer );
        FREE( buffer );

        buffer = realloc( NULL, 256 );
        printf( "case NULL,256: %p\n", buffer );
        FREE( buffer );

        return 0;
On NetBSD gcc 2.95.3 the native "realloc" conforms:

/usr/home/conrad/work:$ gcc -dumpversion
/usr/home/conrad/work:$ gcc VC6test.c
/usr/home/conrad/work:$ ls -l
total 16
-rw-rw-r--  1 conrad  conrad   360 Apr  7 10:43 VC6test.c
-rwxrwxr-x  1 conrad  conrad  6191 Apr  7 10:43 a.out
/usr/home/conrad/work:$ ./a.out
Hello World!
case NULL,0: 0x805b030
case NULL,256: 0x805b000
On Windows 2000 VC 6.0 the native "realloc" conforms:

Hello World!
case NULL,0: 002F07A8
case NULL,256: 002F07A8


reply via email to

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