[ovs-dev] [warnings 3/3] bridge: Properly test for out-of-range values.
Ethan Jackson
ethan at nicira.com
Fri Apr 15 19:24:14 UTC 2011
You are going to have merge conflicts with this patch I suspect, but
the approach seems fine to me.
Ethan
On Fri, Apr 15, 2011 at 9:41 AM, Ben Pfaff <blp at nicira.com> wrote:
> This code was trying to check for priorities greater than UINT16_MAX and
> reset them, but it assigned the value to a uint16_t before it checked it,
> which of course hid the problem.
>
> Fixes the following GCC warning:
>
> vswitchd/bridge.c:3034: warning: comparison is always false due to limited
> range of data type
>
> Reported-by: YAMAMOTO Takashi <yamamoto at valinux.co.jp>
> ---
> vswitchd/bridge.c | 16 ++++++++++------
> 1 files changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
> index 26b4f70..5656b86 100644
> --- a/vswitchd/bridge.c
> +++ b/vswitchd/bridge.c
> @@ -3020,21 +3020,25 @@ enable_lacp(struct port *port, bool *activep)
> static struct lacp_settings *
> port_reconfigure_bond_lacp(struct port *port, struct lacp_settings *s)
> {
> + int priority;
> +
> if (!enable_lacp(port, &s->active)) {
> return NULL;
> }
>
> s->name = port->name;
> memcpy(s->id, port->bridge->ea, ETH_ADDR_LEN);
> - s->priority = atoi(get_port_other_config(port->cfg, "lacp-system-priority",
> - "0"));
> +
> + /* Prefer bondable links if no priority specified. */
> + priority = atoi(get_port_other_config(port->cfg, "lacp-system-priority",
> + "0"));
> + s->priority = (priority > 0 && priority <= UINT16_MAX
> + ? priority
> + : UINT16_MAX - !list_is_short(&port->ifaces));
> +
> s->fast = !strcmp(get_port_other_config(port->cfg, "lacp-time", "slow"),
> "fast");
>
> - if (s->priority <= 0 || s->priority > UINT16_MAX) {
> - /* Prefer bondable links if unspecified. */
> - s->priority = UINT16_MAX - !list_is_short(&port->ifaces);
> - }
> return s;
> }
>
> --
> 1.7.1
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
>
More information about the dev
mailing list