how has C bitten you?

John Mashey mash at mips.UUCP
Wed Aug 14 05:28:41 AEST 1985


> > 	Here's one that just got me:
> > 
> > 		if (sv > score);   <----- note extraneous semi-colon
> > 			score = sv;
> I have seen this bug many times, especially in code written by people
> who routinely switch programming languages....  There was a paper given at a
> USENIX (Toronto?) describing an experiment with different program layout
> techniques. The programs were written without any explicit grouping brackets,
> and were specified by the layout and indentation. A program filter would
> add all the required brackets and buzzard wings before feeding it to the
> compiler.

As I recall, there was a related bug in MERT, way back, of the form:

	if (something)
		stmt1;
		stmt2;
		stmt3;
where the the {}'s were "invisible".

The one I always remember most of the C bites was the truly infamous
bug in chksum in uucp/pk0.c.  (This was actually a code bug, masked by
bug in VAX compiler and irrelevant on 16-bit machines; it caused almost
every 68K port (that used the MIT C compiler, anyway) to break uucp, in that
the 68Ks could talk to each other, but not to VAXEn or 16-bit machines).
The bug was in lines of code that looked like:
	short s;
	unsigned short t;
	...
	if ((unsigned) s <= t) ...
where they really meant  if ((unsigned short)s <= t).
The VAX did (incorrectly) a 16-bit compare, rather than all of the
correct conversions. I'd call this a C bite, simply because psychologically,
it "feels" like (unsigned) type should mean (unsigned type) type,
although it clearly does not.
-- 
-john mashey
UUCP: 	{decvax,ucbvax,ihnp4}!decwrl!mips!mash
DDD:  	415-960-1200
USPS: 	MIPS Computer Systems, 1330 Charleston Rd, Mtn View, CA 94043



More information about the Comp.lang.c mailing list