Re: Missing warning about uninitialized variable.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2007/11/29, eschenb@xxxxxxxxxxxxxxxxxxxxxxxxxxx
<eschenb@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> Hi again,
>
> What I meant is: argc never is 10 in your example, thus gurka is always
> not initialized and therefore has a random value, which is perfectly
> normal.
>
> If gcc should warn about it being potentially not initialized, and if so,
> using which command line options - that's a completely different topic.
>
> Regards
>
> -Sven
>
>
> > On 2007/11/29, eschenb@xxxxxxxxxxxxxxxxxxxxxxxxxxx
> > <eschenb@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> >> Aside from the fact, that you obviously forgot a #include <stdio.h>,
> >> of course the output is random, if the variable stays uninitialized
> >> (./foo
> >> $seq 1 10) has an argc of 11, doesn't it?
> >>
> >> Regards
> >>
> >> -Sven
> >>
> >> > On 2007/11/29, Mikael Vidstedt <mikael.vidstedt@xxxxxxx> wrote:
> >> >> The following program may make use of an uninitialized variable
> >> (gurka):
> >> >>
> >> >> int
> >> >> main(int argc, char* argv[])
> >> >> {
> >> >>    int gurka;
> >> >>
> >> >>    if(argc == 10) {
> >> >>       gurka = 3;
> >> >>    }
> >> >>
> >> >>    // gurka isn't necessarily initialized here...
> >> >>    printf("%d\n", gurka);
> >> >>
> >> >>    return 0;
> >> >> }
> >> >>
> >> >> GCC 4.0 will give a warning when this program is compiled with "-O
> >> >> -Wall". GCC 4.1 and 4.2 do not give that warning. I haven't had the
> >> >> possibility to try GCC 4.3.
> >> >>
> >> >> What say ye?
> >> >>
> >> >> Thanks,
> >> >> Mikael
> >> >
> >> > It prints stochasticly random data too.
> >> >
> >> > gcc version 4.2.3 20071031 (prerelease)
> >> >
> >> > $ gcc -Wall -o foo foo.c
> >> > foo.c: In function 'main':
> >> > foo.c:11: warning: implicit declaration of function 'printf'
> >> > foo.c:11: warning: incompatible implicit declaration of built-in
> >> > function 'printf'
> >> > $ for i in $(seq 1 5); do ./foo $(seq 1 10) ; done
> >> > -1209020420
> >> > -1208291332
> >> > -1208422404
> >> > -1208803332
> >> > -1208823812
> >> > $
> >> >
> >> >    J.C.Pizarro
> >
> > It can be other bug more!
> >

Yes eschenb, they are 11 args, but i've found a weird thing.

With -O, -O1, -O2, -O3, they print 5 times of value 3 (when argc == 11)
Without optimization, it prints stochasticly random data (when argc == 11).

Why is it false positive to say it prints 3 when it should print
random data instead of 3 because argc != 10?

There is some strange in the generated program.

For large projects with uninitialized variables, the behaviour
could be stochasticly flawed as a russian roulette.

 J.C.Pizarro

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux