lua-users home
lua-l archive

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

> There is one warning on Mac OS X (10.10) when compiling in Xcode 6.1.1 with default warnings enabled:
> /Users/jean-luc/Developpement/lua-5.3.0 - xcode/src/liolib.c:480:16: warning: variable 'c' may be uninitialized when used here [-Wconditional-uninitialized]
>   if (!chop && c == '\n')  /* want a newline and have one? */
>                ^
> /Users/jean-luc/Developpement/lua-5.3.0 - xcode/src/liolib.c:467:8: note: initialize the variable 'c' to silence this warning
>   int c;
>        ^
> This is a false positive, but hard for the compiler to detect that c is always initialized… :-)

It is not that hard: the only branch in the path from the function head
to the first assignment to 'c' is obviously false (jump if not (0 <
some-non-zero-constant)).  I am afraid that solving this warning with
a useless initialization can generate warnings in smarter compilers
("value is never used"). I tried to change the code to make it more
"obvious" that 'c' cannot be used uninitialized, but could not find a
good solution.

-- Roberto