[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ft-devel] WIP PATCH: clang static analyzer and warning fixes
From: |
Behdad Esfahbod |
Subject: |
Re: [ft-devel] WIP PATCH: clang static analyzer and warning fixes |
Date: |
Wed, 18 Jun 2014 16:11:42 -0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 |
On 14-06-18 01:05 AM, Werner LEMBERG wrote:
>
>
> It's not *that* mysterious! The code looks like this.
>
> bool flag = 0;
>
> while {
> int a;
>
> ...
> if (flag)
> a = 1;
> else
> a = 0;
> ...
> flag = 1;
> }
It doesn't. It looks like this:
while {
int a;
...
if (x) {
if (flag)
a = 1;
else
a = 0;
}
...
flag = 1;
}
Where x is sometimes not ture. I'm fairly confident that the value of "a" is
undefined at the start of every iteration of the loop. Ie. it's not
guaranteed to be retained. As such, if there's any iteration that you do NOT
assign a value to it, it's undefined. I'm researching this more. But as I
said, I'm fairly confident that is the case.
> Normally, compilers can recognize that initializations happen within
> an if-else clause. But apparently clang and MSVC try to be clever...
They are doing the right thing.
> FreeType's `make devel' activates *a lot* of gcc warnings, but I don't
> get something similar.
>
> I've now changed this to
>
> int a = 0;
> bool flag = 0;
This is correct.
> while {
> ...
> if (flag)
> a = 1;
> else
> a = 0;
> ...
> flag = 1;
> }
>
>
> Werner
>
> _______________________________________________
> Freetype-devel mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/freetype-devel
>
--
behdad
http://behdad.org/