Re: commit -- fixed a potential bug


Subject: Re: commit -- fixed a potential bug
From: Sam TH (sam@uchicago.edu)
Date: Mon Feb 19 2001 - 16:01:32 CST


On Mon, Feb 19, 2001 at 05:31:07PM +0100, Jesper Skov wrote:
> >>>>> "Sam" == Sam TH <sam@uchicago.edu> writes:
>
> Sam> Instead of assigning, we were comparing. Bad. Changed a
> Sam> potentially bad comparison to an assignment. That could have
> Sam> been a hard-to-find bug. :)
>
> Surely the compiler should have been bitching about expression without
> side effect. We use -Wall on GCC. It's usually quite good at catching
> something like that.

The compiler was complaining, which was how I found it. But if you
were looking for that bug, it would have been harder to find.

>
> As for assignments which should have been comparisons, I'd like to
> advocate a defensive programming style:
>
> Instead of:
>
> (foo == CONST_OF_ONE_FORM_OR_ANOTHER)
>
> use:
>
> (CONST_OF_ONE_FORM_OR_ANOTHER == foo)
>
> Then you'll get a compiler error if you accidently forget one of the
> equal characters.

We already do this in lots of places, and where we don't, we should.
           
        sam th
        sam@uchicago.edu
        http://www.abisource.com/~sam/
        GnuPG Key:
        http://www.abisource.com/~sam/key




This archive was generated by hypermail 2b25 : Mon Feb 19 2001 - 15:58:40 CST