[FRIAM] div. zero bugs?

Marcus G. Daniels mgd at santafe.edu
Thu Oct 26 00:16:04 EDT 2006


Owen Densmore wrote:
> So the *extremely* common bug  
> of using = rather than == causes entirely unexpected consequences ..  
> launching a missile.
>   
I expect to see both in many circumstances.
For example, when opening a file to read that is absent or to write, and 
write permission is forbidden.

if ((fp = fopen (filename, "r")) == NULL)
abort ();

I haven't really created many bugs because of "=" vs. "==". GCC even 
gives a warning...

$ cat t.c
#include <stdio.h>
#include <stdlib.h>

static void
launch_missle ()
{
printf ("Missle launched\n");
}

int
main (int argc, const char **argv)
{
int red_button_pressed = 0;

if (argc > 1)
red_button_pressed = atoi (argv[1]);

if (red_button_pressed = 1)
launch_missle ();

return 0;
}


$ gcc -Wall t.c
t.c: In function ‘main’:
t.c:18: warning: suggest parentheses around assignment used as truth value





More information about the Friam mailing list