Found a TC 2.0 bug... ?

Ajay Shah ajayshah at alhena.usc.edu
Sun Apr 28 17:57:21 AEST 1991


I think I have identified a bug in TC 2.0.

My machine has 645k of free memory.  I bring up the TC environment 
(not using tcc here).  I've set the memory model to be Huge.
I run this program:
---------------------------------------------------------------------------
1	#include <stdio.h>
2	#include <malloc.h>
3	void
4	main()
5	{
6	    int i;
7	    char *ptr;
8	    ptr = (char *)malloc((unsigned) 0);
9	    for (i=1;i<=1024;i+=i){
10		ptr = (char *)realloc(ptr,(unsigned)i*1024);
11		if (ptr == (char *)NULL) printf("realloc bombed when ");
12		printf("%d Kbytes realloced\n",i);
13	    }
14	}
15
---------------------------------------------------------------------------

I get this output:
---------------------------------------------------------------------------
1 Kbytes realloced
2 Kbytes realloced
4 Kbytes realloced
8 Kbytes realloced
16 Kbytes realloced
32 Kbytes realloced
realloc bombed when 64 Kbytes realloced
realloc bombed when 128 Kbytes realloced
realloc bombed when 256 Kbytes realloced
realloc bombed when 512 Kbytes realloced
realloc bombed when 1024 Kbytes realloced
---------------------------------------------------------------------------

Question: why does he have problems allocating > 64k???  Is the
culprit Intel or Borland?

Now watch.  Instead of taking RAM in steps of 1024 bytes, I use
steps of 1000 bytes.  Ie., I change line 10 to be

ptr = (char *)realloc(ptr,(unsigned)i*1000);

Now it works!!  It goes ahead and reallocs me 1Meg without complaining!
There's no way I can have this kind of free RAM on a 8086!!
-- 
_______________________________________________________________________________
Ajay Shah, (213)734-3930, ajayshah at usc.edu
                             The more things change, the more they stay insane.
_______________________________________________________________________________



More information about the Comp.lang.c mailing list