Portable C Compiler Bug

Anne M. Holler amh at uvacs.cs.Virginia.EDU
Sat Oct 8 00:30:04 AEST 1988


    I have found and fixed a bug in the version of the Portable C compiler
distributed with Berkeley UNIX 4.3.  The bug causes the compiler to some-
times fail giving the error message "schain botch".
    The situation is that in the process of clearing the symbol table at
the end of a block (in the function clearst in the module pftn.c), the
compiler moves into the newly-freed symbol table entries any remaining
entries previously blocked by the removed symbols from hashing into those
positions.  However, pointers to symbol table entries are kept in a linked
list for the block level to which they belong (schain), and these pointers
are not being updated to reflect the moved entries' new locations.
    The bug fix is as follows.  When an entry in the symbol table is moved
into a freed position, its pointer in the schain is found and modified.  A
portion of code from clearst along with the changes necessary is given below.
Existing code:
			if( (r = relook(q)) != q ) {
				*r = *q;
				q->stype = TNULL;
				}
Revised code:
			if( (r = relook(q)) != q ) {
			    struct symtab *sptr, *sptrbak;
				*r = *q;
				/* Fix up mishashed entries' schain values */
				for (sptrbak=sptr=schain[q->slevel]; sptr!=NULL;
				     sptrbak=sptr,sptr=sptr->snext) {
					if (sptr==q) {
						if (sptr == sptrbak)
							schain[q->slevel] = r;
						else
							sptrbak->snext = r;
						break;
						}
					}
				q->stype = TNULL;
				}
    Please feel free to correspond with me about this matter.  Thanks.
Anne Holler



More information about the Comp.bugs.4bsd.ucb-fixes mailing list