Hi,
we are having problems with the combination of malloc and realloc
using WATCOM C/C++ 10.6 .
Consider the following short sample program:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
int main( int argc, char *argv[] )
{
extern char *__nheapbeg;
unsigned **ppu;
char *p, *p3;
int i;
if ( ( p = malloc( 14 ) ) == NULL )
{
perror( “malloc( 14 )” );
exit( 1 );
}
for ( i = 4; ( ppu = (unsigned) (__nheapbeg+0x24) ) > 12; i += 4 )
{
if ( ( p = realloc( p, i ) ) == NULL )
{
perror( “realloc( p, i )” );
exit( 1 );
}
}
p3 = malloc( 3 );
for ( i = 1; ( p = malloc( i ) ) == NULL; i++ )
;
printf( “malloc( 3 ) → %P\n”, p3 );
printf( “malloc( %d ) → %P\n”, i, p );
return 0;
}
With our systems, it yields the output
malloc( 3 ) → 00000000
malloc( 5 ) → 0000CB70
i.e., You can not allocate 3 bytes, but allocating 5 (or more)
bytes is well possible.
Is anyone of the QSSL staff able (and willing) to work on a
solution to this problem?
If so, I can give You some more information on when and where
the problem occurs.
Kind regards,
–
T. Haupt
BitCtrl Systems GmbH
Weissenfelser Str. 67
04229 Leipzig
Phone: +49 (0)341 49067 0
Phax: +49 (0)341 49067 15
eMail: frk bitctrl de