Skip to contentSkip to conversation

Documentation/accounting/getdelays.c intialize the variable before using it

PATCH In review Jaswinder Singh Rajput 3 participants 4 messages May 20, 2009 – May 27, 2009 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Documentation/accounting/getdelays.c intialize the variable before using it

May be in some cases cmd_type will be used uninitialized.

Also fixes compilation warning:

CC [M] Documentation/DocBook/procfs_example.o
Documentation/accounting/getdelays.c: In function ‘main’:
Documentation/accounting/getdelays.c:249: warning: ‘cmd_type’ may be used uninitialized in this function

---
 Documentation/accounting/getdelays.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Documentation/accounting/getdelays.c +1 -1
index 7ea2311..36aae3b 100644
@@ -246,7 +246,7 @@ void print_ioacct(struct taskstats *t)
 
 int main(int argc, char *argv[])
 {
-	int c, rc, rep_len, aggr_len, len2, cmd_type;
+	int c, rc, rep_len, aggr_len, len2, cmd_type = TASKSTATS_CMD_ATTR_UNSPEC;
 	__u16 id;
 	__u32 mypid;
 
Signature · 1 line
1.6.1.1
#1 lore raw
Quoted 28 lines · On Wed, 20 May 2009 10:44:44 +0530 Jaswinder Singh Rajput…

May be in some cases cmd_type will be used uninitialized.

Also fixes compilation warning:

CC [M] Documentation/DocBook/procfs_example.o
Documentation/accounting/getdelays.c: In function ___main___:
Documentation/accounting/getdelays.c:249: warning: ___cmd_type___ may be used uninitialized in this function

---
 Documentation/accounting/getdelays.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Documentation/accounting/getdelays.c +1 -1
index 7ea2311..36aae3b 100644
@@ -246,7 +246,7 @@ void print_ioacct(struct taskstats *t)
 
 int main(int argc, char *argv[])
 {
-	int c, rc, rep_len, aggr_len, len2, cmd_type;
+	int c, rc, rep_len, aggr_len, len2, cmd_type = TASKSTATS_CMD_ATTR_UNSPEC;
 	__u16 id;
 	__u32 mypid;
 
Quoted 1 line

From my reading of the code there is no bug here - we'll only use

cmd_type if tid != 0, and cmd_type is always initialised when tid != 0.

But I suppose we should squish the warning anyway.

btw, whichever version of gcc you're using has apparently regressed - my gcc-4.3.0 manages to work out what's happening. Hence please prefer to include the gcc version in the changelog. And send a bug report at the gcc guys if appropriate ;)

#2 lore raw
Quoted 31 lines · Andrew Morton
Quoted 28 lines · On Wed, 20 May 2009 10:44:44 +0530 Jaswinder Singh Rajput…

May be in some cases cmd_type will be used uninitialized.

Also fixes compilation warning:

CC [M] Documentation/DocBook/procfs_example.o
Documentation/accounting/getdelays.c: In function ___main___:
Documentation/accounting/getdelays.c:249: warning: ___cmd_type___ may be used uninitialized in this function

---
 Documentation/accounting/getdelays.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Documentation/accounting/getdelays.c +1 -1
index 7ea2311..36aae3b 100644
@@ -246,7 +246,7 @@ void print_ioacct(struct taskstats *t)
 
 int main(int argc, char *argv[])
 {
-	int c, rc, rep_len, aggr_len, len2, cmd_type;
+	int c, rc, rep_len, aggr_len, len2, cmd_type = TASKSTATS_CMD_ATTR_UNSPEC;
 	__u16 id;
 	__u32 mypid;
 
Quoted 1 line

From my reading of the code there is no bug here - we'll only use

Quoted 8 lines

cmd_type if tid != 0, and cmd_type is always initialised when tid != 0.

But I suppose we should squish the warning anyway.

btw, whichever version of gcc you're using has apparently regressed - my gcc-4.3.0 manages to work out what's happening. Hence please prefer to include the gcc version in the changelog. And send a bug report at the gcc guys if appropriate ;)

my gcc version is 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC)

But I heard from jejb that 4.3.3 fixed some of these warnings.

Thanks,
--
JSR

Acked-by on v1 1/1
#3 lore raw
In reply to Jaswinder Singh Rajput
Quoted 19 lines · Jaswinder Singh Rajput

May be in some cases cmd_type will be used uninitialized.

Also fixes compilation warning:

CC [M] Documentation/DocBook/procfs_example.o
Documentation/accounting/getdelays.c: In function ???main???:
Documentation/accounting/getdelays.c:249: warning: ???cmd_type??? may be used uninitialized in this function

---
 Documentation/accounting/getdelays.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Documentation/accounting/getdelays.c +0 -0
index 7ea2311..36aae3b 100644

Documentation/accounting/getdelays.c void print_ioacct(struct taskstats *t) · line 249

Quoted 5 lines
Documentation/accounting/getdelays.c +1 -1
@@ -246,7 +246,7 @@ void print_ioacct(struct taskstats *t)
 
 int main(int argc, char *argv[])
 {
-	int c, rc, rep_len, aggr_len, len2, cmd_type;
+	int c, rc, rep_len, aggr_len, len2, cmd_type = TASKSTATS_CMD_ATTR_UNSPEC;

Thanks. The fix seems correct

I am away traveling with almost no time to check emails, hence I've been slow responding. Thanks for being patient.

Signature · 1 line
	Balbir