Discussion:
[ast-developers] -O2 -Wuninitialized warnings ast-ksh.2013-08-14
ольга крыжановская
2013-08-26 13:59:27 UTC
Permalink
In ast-ksh.2013-08-14 gcc, clang and Sun Studio 12.3 lint report the
following variables as uninitialized, when compiling the package with
-O2 (this is mandatory to allow the gcc and clang compilers to "see"
uninitialized variables, lint does not require this).
AFAIK the warnings, bogus or not, must be fixed before we can
integrate the current ksh version into Dilos/Illumos (their rules say
so) and Red Flag Linux (they like to have it):

gcc 4.7 reports these variables as uninitialized:
src/lib/libast/misc/spawnvex.c:1100:15: warning: 'flags' may be used
uninitialized in this function [-Wuninitialized]
src/lib/libcmd/grep.c:417:18: warning: 'file' may be used
uninitialized in this function [-Wuninitialized]
src/lib/libcmd/grep.c:418:18: warning: 'line' may be used
uninitialized in this function [-Wuninitialized]
src/lib/libcmd/grep.c:419:5: warning: 'f' may be used uninitialized in
this function [-Wuninitialized]
src/cmd/ksh93/sh/arith.c:322:28: warning: 'np' may be used
uninitialized in this function [-Wuninitialized]

clang 3.3 and Sun Studio lint report these variables as uninitialized:
src/lib/libast/misc/spawnvex.c:1100:9: warning: variable 'flags' is
uninitialized when used here [-Wuninitialized]
src/cmd/ksh93/sh/arith.c:322:29: warning: variable 'np' is
uninitialized when used here [-Wuninitialized]

I know that "src/lib/libast/misc/spawnvex.c:1100:15: warning: 'flags'"
has been contentious, in the past, but now two compilers and Sun
Studio lint are unable to determinate whether the 'flags' variable is
always initialized, or not, and thus I think, we should bite into a
sour apple and just do a flags = 0; to make the compilers shut up.
Otherwise we have to explain to Dilos/Illumos and Red Flag linux in
detail, why we break their rules, and try to get away with that.

I have attached the patch, I made using Roland's build machine.

Olga
--
, _ _ ,
{ \/`o;====- Olga Kryzhanovska -====;o`\/ }
.----'-/`-/ olga.kryzhanovska at gmail.com \-`\-'----.
`'-..-| / http://twitter.com/fleyta \ |-..-'`
/\/\ Solaris/BSD//C/C++ programmer /\/\
`--` `--`
-------------- next part --------------
diff -r -u src/cmd/ksh93/sh/arith.c src/cmd/ksh93/sh/arith.c
--- src/cmd/ksh93/sh/arith.c 2013-08-12 16:43:47.000000000 +0200
+++ src/cmd/ksh93/sh/arith.c 2013-08-26 15:36:45.357470621 +0200
@@ -253,7 +253,7 @@
c = mbchar(str);
if(isaletter(c))
{
- register Namval_t *np;
+ register Namval_t *np = NULL;
int dot=0;
while(1)
{
diff -r -u src/lib/libast/misc/spawnvex.c src/lib/libast/misc/spawnvex.c
--- src/lib/libast/misc/spawnvex.c 2013-05-03 17:15:00.000000000 +0200
+++ src/lib/libast/misc/spawnvex.c 2013-08-26 15:41:50.419406532 +0200
@@ -793,7 +793,7 @@
{
int i;
int op;
- unsigned int flags;
+ unsigned int flags = 0;
pid_t pid;
#if _lib_posix_spawn
int arg;
@@ -875,7 +875,6 @@
}
else
{
- flags = 0;
xev = 0;
}
#if _lib_spawn_mode
diff -r -u src/lib/libcmd/grep.c src/lib/libcmd/grep.c
--- src/lib/libcmd/grep.c 2013-04-22 08:36:25.000000000 +0200
+++ src/lib/libcmd/grep.c 2013-08-26 15:43:20.882836180 +0200
@@ -312,15 +312,15 @@
static int
compile(State_t* state)
{
- int line;
+ int line = 0;
int c;
int r;
size_t n;
char* s;
char* t;
- char* file;
+ char* file = NULL;
Item_t* x;
- Sfio_t* f;
+ Sfio_t* f = NULL;

r = 1;
if (!(state->tmp = sfstropen()))
Roland Mainz
2013-09-16 23:59:16 UTC
Permalink
On Mon, Aug 26, 2013 at 3:59 PM, ????? ????????????
Post by ольга крыжановская
In ast-ksh.2013-08-14 gcc, clang and Sun Studio 12.3 lint report the
following variables as uninitialized, when compiling the package with
-O2 (this is mandatory to allow the gcc and clang compilers to "see"
uninitialized variables, lint does not require this).
AFAIK the warnings, bogus or not, must be fixed before we can
integrate the current ksh version into Dilos/Illumos (their rules say
src/lib/libast/misc/spawnvex.c:1100:15: warning: 'flags' may be used
uninitialized in this function [-Wuninitialized]
src/lib/libcmd/grep.c:417:18: warning: 'file' may be used
uninitialized in this function [-Wuninitialized]
src/lib/libcmd/grep.c:418:18: warning: 'line' may be used
uninitialized in this function [-Wuninitialized]
src/lib/libcmd/grep.c:419:5: warning: 'f' may be used uninitialized in
this function [-Wuninitialized]
src/cmd/ksh93/sh/arith.c:322:28: warning: 'np' may be used
uninitialized in this function [-Wuninitialized]
src/lib/libast/misc/spawnvex.c:1100:9: warning: variable 'flags' is
uninitialized when used here [-Wuninitialized]
src/cmd/ksh93/sh/arith.c:322:29: warning: variable 'np' is
uninitialized when used here [-Wuninitialized]
I know that "src/lib/libast/misc/spawnvex.c:1100:15: warning: 'flags'"
has been contentious, in the past, but now two compilers and Sun
Studio lint are unable to determinate whether the 'flags' variable is
always initialized, or not, and thus I think, we should bite into a
sour apple and just do a flags = 0; to make the compilers shut up.
Otherwise we have to explain to Dilos/Illumos and Red Flag linux in
detail, why we break their rules, and try to get away with that.
I have attached the patch, I made using Roland's build machine.
Erm... ping! ...

... the patch was never applied and some of the uninitalised warnings
are *real* issues which should be fixed. And see Olga's comments about
distribution policies... some of them do not take updates which cause
new -Wuninitalized warnings to appear...

----

Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
-------------- next part --------------
diff -r -u src/cmd/ksh93/sh/arith.c src/cmd/ksh93/sh/arith.c
--- src/cmd/ksh93/sh/arith.c 2013-08-12 16:43:47.000000000 +0200
+++ src/cmd/ksh93/sh/arith.c 2013-08-26 15:36:45.357470621 +0200
@@ -253,7 +253,7 @@
c = mbchar(str);
if(isaletter(c))
{
- register Namval_t *np;
+ register Namval_t *np = NULL;
int dot=0;
while(1)
{
diff -r -u src/lib/libast/misc/spawnvex.c src/lib/libast/misc/spawnvex.c
--- src/lib/libast/misc/spawnvex.c 2013-05-03 17:15:00.000000000 +0200
+++ src/lib/libast/misc/spawnvex.c 2013-08-26 15:41:50.419406532 +0200
@@ -793,7 +793,7 @@
{
int i;
int op;
- unsigned int flags;
+ unsigned int flags = 0;
pid_t pid;
#if _lib_posix_spawn
int arg;
@@ -875,7 +875,6 @@
}
else
{
- flags = 0;
xev = 0;
}
#if _lib_spawn_mode
diff -r -u src/lib/libcmd/grep.c src/lib/libcmd/grep.c
--- src/lib/libcmd/grep.c 2013-04-22 08:36:25.000000000 +0200
+++ src/lib/libcmd/grep.c 2013-08-26 15:43:20.882836180 +0200
@@ -312,15 +312,15 @@
static int
compile(State_t* state)
{
- int line;
+ int line = 0;
int c;
int r;
size_t n;
char* s;
char* t;
- char* file;
+ char* file = NULL;
Item_t* x;
- Sfio_t* f;
+ Sfio_t* f = NULL;

r = 1;
if (!(state->tmp = sfstropen()))
Loading...