Message ID | 20220225200251.1139353-1-mkp@redhat.com |
---|---|
State | Superseded |
Headers | show |
Series | [ovs-dev,v1] ofp-packet: Silence the 'may be uninitialized' warning. | expand |
Context | Check | Description |
---|---|---|
ovsrobot/apply-robot | success | apply and check: success |
ovsrobot/github-robot-_Build_and_Test | success | github build: passed |
ovsrobot/intel-ovs-compilation | success | test: success |
On 2/25/2022 12:02 PM, Mike Pattrick wrote: > GCC 11.2.1-2.2 emits a false-positive warnings like: > > lib/ofp-packet.c: In function 'ofputil_decode_packet_in': > lib/ofp-packet.c:155:25: warning: 'reason' may be used > uninitialized [-Wmaybe-uninitialized] > lib/ofp-packet.c: In function 'ofputil_decode_packet_in_private': > lib/ofp-packet.c:886:27: warning: 'value' may be used > uninitialized [-Wmaybe-uninitialized] > > The caller doesn't happen to use the variables in these cases because > an error is set. But checking for the error resolves this warning. > > Signed-off-by: Mike Pattrick <mkp@redhat.com> > --- > lib/ofp-packet.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/lib/ofp-packet.c b/lib/ofp-packet.c > index 4579548ee..81b3ebac6 100644 > --- a/lib/ofp-packet.c > +++ b/lib/ofp-packet.c > @@ -152,7 +152,9 @@ decode_nx_packet_in2(const struct ofp_header *oh, bool loose, > case NXPINT_REASON: { > uint8_t reason; > error = ofpprop_parse_u8(&payload, &reason); > - pin->reason = reason; > + if (!error) { > + pin->reason = reason; > + } > break; > } > > @@ -883,7 +885,9 @@ ofputil_decode_packet_in_private(const struct ofp_header *oh, bool loose, > case NXCPT_ODP_PORT: { > uint32_t value; > error = ofpprop_parse_u32(&payload, &value); > - pin->odp_port = u32_to_odp(value); > + if (!error) { > + pin->odp_port = u32_to_odp(value); > + } > break; > } > Hi Mike, Thanks for the patch. It looks reasonable. Question though? Are these the only false positives for an entire build? Seems to me this might be the sort of thing that occurs elsewhere. Thanks, - Greg
On Fri, Feb 25, 2022 at 4:43 PM Gregory Rose <gvrose8192@gmail.com> wrote: > > > > On 2/25/2022 12:02 PM, Mike Pattrick wrote: > > GCC 11.2.1-2.2 emits a false-positive warnings like: > > > > lib/ofp-packet.c: In function 'ofputil_decode_packet_in': > > lib/ofp-packet.c:155:25: warning: 'reason' may be used > > uninitialized [-Wmaybe-uninitialized] > > lib/ofp-packet.c: In function 'ofputil_decode_packet_in_private': > > lib/ofp-packet.c:886:27: warning: 'value' may be used > > uninitialized [-Wmaybe-uninitialized] > > > > The caller doesn't happen to use the variables in these cases because > > an error is set. But checking for the error resolves this warning. > > > > Signed-off-by: Mike Pattrick <mkp@redhat.com> > > --- > > lib/ofp-packet.c | 8 ++++++-- > > 1 file changed, 6 insertions(+), 2 deletions(-) > > > > diff --git a/lib/ofp-packet.c b/lib/ofp-packet.c > > index 4579548ee..81b3ebac6 100644 > > --- a/lib/ofp-packet.c > > +++ b/lib/ofp-packet.c > > @@ -152,7 +152,9 @@ decode_nx_packet_in2(const struct ofp_header *oh, bool loose, > > case NXPINT_REASON: { > > uint8_t reason; > > error = ofpprop_parse_u8(&payload, &reason); > > - pin->reason = reason; > > + if (!error) { > > + pin->reason = reason; > > + } > > break; > > } > > > > @@ -883,7 +885,9 @@ ofputil_decode_packet_in_private(const struct ofp_header *oh, bool loose, > > case NXCPT_ODP_PORT: { > > uint32_t value; > > error = ofpprop_parse_u32(&payload, &value); > > - pin->odp_port = u32_to_odp(value); > > + if (!error) { > > + pin->odp_port = u32_to_odp(value); > > + } > > break; > > } > > > > Hi Mike, > > Thanks for the patch. It looks reasonable. Question though? Are these > the only false positives for an entire build? Seems to me this might be > the sort of thing that occurs elsewhere. These were the only ones identified by GCC, but looking through the code I see a few other locations with the same pattern, will send a v2. -M > Thanks, > > - Greg >
diff --git a/lib/ofp-packet.c b/lib/ofp-packet.c index 4579548ee..81b3ebac6 100644 --- a/lib/ofp-packet.c +++ b/lib/ofp-packet.c @@ -152,7 +152,9 @@ decode_nx_packet_in2(const struct ofp_header *oh, bool loose, case NXPINT_REASON: { uint8_t reason; error = ofpprop_parse_u8(&payload, &reason); - pin->reason = reason; + if (!error) { + pin->reason = reason; + } break; } @@ -883,7 +885,9 @@ ofputil_decode_packet_in_private(const struct ofp_header *oh, bool loose, case NXCPT_ODP_PORT: { uint32_t value; error = ofpprop_parse_u32(&payload, &value); - pin->odp_port = u32_to_odp(value); + if (!error) { + pin->odp_port = u32_to_odp(value); + } break; }
GCC 11.2.1-2.2 emits a false-positive warnings like: lib/ofp-packet.c: In function 'ofputil_decode_packet_in': lib/ofp-packet.c:155:25: warning: 'reason' may be used uninitialized [-Wmaybe-uninitialized] lib/ofp-packet.c: In function 'ofputil_decode_packet_in_private': lib/ofp-packet.c:886:27: warning: 'value' may be used uninitialized [-Wmaybe-uninitialized] The caller doesn't happen to use the variables in these cases because an error is set. But checking for the error resolves this warning. Signed-off-by: Mike Pattrick <mkp@redhat.com> --- lib/ofp-packet.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)