[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pcc-list
Subject:    Re: memory management issues
From:       Anders Magnusson <ragge () ludd ! ltu ! se>
Date:       2007-09-29 12:30:37
Message-ID: 46FE456D.8070007 () ludd ! ltu ! se
[Download RAW message or body]

Really great, Otto!  Thanks!  These bugs may be difficult to find.


Otto Moerbeek wrote:
> On Wed, 26 Sep 2007, Otto Moerbeek wrote:
>
>
> The pftn.c part is not stricly neccesary, it only prevent printing
> strange pointer values when using -Xd.
>   
No reason not to clear them anyway, it's usually simpler to find bugs due to
null pointers than random pointers.

> A little more explanation is in place. I added some debug code and saw
> the init code walk the fields of a struct. The array of fields
> references looked like this:
>
> in_xp[0] = valid pointer
> in_xp[1] = valid pointer
> in_xp[2] = NULL
> in_xp[3] = 0xd0d0d0d0
>
> in_xp gets bumped in two places (see the diff). After two bumps,
> in_xp[0] = NULL and in_xp[1] = 0xd0d0d0d0.
>
> So the test of in_xp[1] sees a non-NULL value, and in_xp gets bumped
> past the end of the array. 
>
> If this is a case of "it should not happen that in_xp[0] is NULL" we
> should hunt how this can happen.
>   
The init code is greasy at least, it was that already 30 years ago due 
to the
old docs and hasn't become clearer when I added support for element
initialization.  I think the best to do is to get it work correct and then
leave it.

-- Ragge

> 	-Otto
>
>   
>> Index: cc/ccom/init.c
>> ===================================================================
>> RCS file: /cvs/src/usr.bin/pcc/cc/ccom/init.c,v
>> retrieving revision 1.6
>> diff -u -p -r1.6 init.c
>> --- cc/ccom/init.c	25 Sep 2007 05:51:44 -0000	1.6
>> +++ cc/ccom/init.c	26 Sep 2007 09:34:07 -0000
>> @@ -327,7 +327,7 @@ stkpop(void)
>>  		printf("stkpop\n");
>>  #endif
>>  	for (; pstk; pstk = pstk->in_prev) {
>> -		if (pstk->in_t == STRTY) {
>> +		if (pstk->in_t == STRTY && pstk->in_xp[0] != NULL) {
>>  			pstk->in_xp++;
>>  			if (*pstk->in_xp != NULL)
>>  				break;
>> @@ -732,7 +732,7 @@ irbrace()
>>  		if (ISARY(pstk->in_t))
>>  			pstk->in_n = pstk->in_df->ddim;
>>  		else if (pstk->in_t == STRTY) {
>> -			while (pstk->in_xp[1] != NULL)
>> +			while (pstk->in_xp[0] != NULL && pstk->in_xp[1] != NULL)
>>  				pstk->in_xp++;
>>  		}
>>  		stkpop();
>> Index: cc/ccom/pftn.c
>> ===================================================================
>> RCS file: /cvs/src/usr.bin/pcc/cc/ccom/pftn.c,v
>> retrieving revision 1.4
>> diff -u -p -r1.4 pftn.c
>> --- cc/ccom/pftn.c	23 Sep 2007 20:13:28 -0000	1.4
>> +++ cc/ccom/pftn.c	26 Sep 2007 09:23:59 -0000
>> @@ -2512,6 +2512,9 @@ getsymtab(char *name, int flags)
>>  	s->sflags = flags & SMASK;
>>  	s->soffset = 0;
>>  	s->slevel = blevel;
>> +	s->sdf = NULL;
>> +	s->ssue = NULL;
>> +	s->suse = 0;
>>  	return s;
>>  }
>>  
>>
>>  
>>
>>
>>     

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic