[ovs-dev] [PATCH] odp-util: fix a compiler warning

Ben Pfaff blp at ovn.org
Mon Jan 15 19:24:25 UTC 2018


On Sat, Jan 13, 2018 at 04:21:51PM -0500, Aaron Conole wrote:
> The result of a ternary operation will be promoted at least to int
> type.  As such, the compiler may generate a warning as:
>   format specifies type 'unsigned char' but the argument has type 'int'
> 
> This commit explicitly casts the result to avoid the warning.
> 
> Fixes: 74c4530dca93 ("ofproto-dpif: Don't slow-path controller actions with pause.")
> Cc: Justin Pettit <jpettit at ovn.org>
> Signed-off-by: Aaron Conole <aconole at bytheb.org>
> ---
>  lib/odp-util.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/odp-util.c b/lib/odp-util.c
> index af995efca..16f9bcd54 100644
> --- a/lib/odp-util.c
> +++ b/lib/odp-util.c
> @@ -488,8 +488,8 @@ format_odp_userspace_action(struct ds *ds, const struct nlattr *attr,
>                                ",controller_id=%"PRIu16
>                                ",max_len=%"PRIu16,
>                                cookie.controller.reason,
> -                              cookie.controller.dont_send ? 1 : 0,
> -                              cookie.controller.continuation ? 1 : 0,
> +                              (uint8_t)(cookie.controller.dont_send ? 1 : 0),
> +                              (uint8_t)(cookie.controller.continuation ? 1 : 0),
>                                cookie.controller.recirc_id,
>                                ntohll(get_32aligned_be64(
>                                           &cookie.controller.rule_cookie)),

Thanks for working to avoid warnings!

I normally prefer to avoid casts (and the coding style document
generally supports that), so I'd prefer to change the "%"PRIu8 to just
"%d" (which matches the type of 1 and 0).

Thanks,

Ben.


More information about the dev mailing list