smbfs bug introduced at smbfs_vnops.c:1.58

Daniel Ellard ellard at eecs.harvard.edu
Sun Apr 10 05:44:45 PDT 2005


On Sun, 10 Apr 2005, Dimitry Andric wrote:

> > If you change the -O to -g, then the code for "a" is not
> > removed -- but there's still no warning.  I think this is
> > a bug, because if the expression wasn't an innocuous a+=1
> > it could be a real problem if the variable wasn't removed.
>
> The idea here is that gcc sees that the value of a is never used, and
> therefore it doesn't have to warn.  (Whether you agree with this, or
> not, is more of a political or philosophical question. ;)  But as soon
> as you actually *do* something with a's value afterwards, it will
> start to complain.

Well, I guess have to give an example...

int main(void) {
        int a;
	int b[1];

	a = b[a * 10000];	/* Uses the value of a. */
	return (0);
}

If you compile this with -O, then the "a = " line is
optimized away, and the deref of some random piece
of memory goes away.

If you compile this without the -O then now you
have a deref to something whose address depends
on an uninitialized variable.  Sorry, that's bad.

At least the gcc folk now do detect this old chestnut:

	{
	    int a;

	    a /= 0;
	}

which was used to provoke arguments in compiler
classes for many years.  (Optimized, nothing happens.
Unoptimized, a division-by-zero error happens...)

My philosophy is that the compiler should warn
you about things in the un-optimized, un-transformed
code (because that's where I put my bugs -- if I've
written code that has no effect, that's probably not
what I meant).  I'd rather get extraneous warnings
than miss something.  Of course, everyone is welcome
to their own philosophy.  (But how politics enter
into this, I don't want to know.)

-Dan



More information about the freebsd-fs mailing list