Discussion:
[Linuxptp-devel] [PATCH] phc2sys: fix maybe uninitialized warnings
Petr Kulhavy
2017-05-21 20:32:10 UTC
Permalink
Fix "may be used uninitialized in this function" warnings for state and
timestamping.

Signed-off-by: Petr Kulhavy <***@jikos.cz>
---
phc2sys.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/phc2sys.c b/phc2sys.c
index 4c8b552..f3cfed8 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -1037,7 +1037,7 @@ static int auto_init_ports(struct node *node, int add_rt)
struct clock *clock;
int number_ports, res;
unsigned int i;
- int state, timestamping;
+ int state = 0, timestamping = 0;
char iface[IFNAMSIZ];

while (1) {
--
2.7.4
Richard Cochran
2017-05-22 05:11:45 UTC
Permalink
Post by Petr Kulhavy
Fix "may be used uninitialized in this function" warnings for state and
timestamping.
Please tell us more:

What gcc version produces this warning?

Is the warning a false positive or not?
Post by Petr Kulhavy
@@ -1037,7 +1037,7 @@ static int auto_init_ports(struct node *node, int add_rt)
struct clock *clock;
int number_ports, res;
unsigned int i;
- int state, timestamping;
+ int state = 0, timestamping = 0;
These two variables hold enumation values and should be initialized as
such, ie. PS_xxx and TS_xxx.

Thanks,
Richard
Petr Kulhavy
2017-05-22 20:43:06 UTC
Permalink
gcc 4.8.3, gcc 5.4.0 and maybe other.

The warning is a "false positive" in the sense that the compiler is not
able to follow the logic when run_pmc_port_properties() sets state and
timestamping.
But the actual variables are never uses uninitialized.

Regards
Petr
Post by Richard Cochran
Post by Petr Kulhavy
Fix "may be used uninitialized in this function" warnings for state and
timestamping.
What gcc version produces this warning?
Is the warning a false positive or not?
Post by Petr Kulhavy
@@ -1037,7 +1037,7 @@ static int auto_init_ports(struct node *node, int add_rt)
struct clock *clock;
int number_ports, res;
unsigned int i;
- int state, timestamping;
+ int state = 0, timestamping = 0;
These two variables hold enumation values and should be initialized as
such, ie. PS_xxx and TS_xxx.
Thanks,
Richard
Loading...