diff mbox series

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

Message ID 20180113212151.9607-1-aconole@bytheb.org
State Changes Requested
Headers show
Series [ovs-dev] odp-util: fix a compiler warning | expand

Commit Message

Aaron Conole Jan. 13, 2018, 9:21 p.m. UTC
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@ovn.org>
Signed-off-by: Aaron Conole <aconole@bytheb.org>
---
 lib/odp-util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Stokes, Ian Jan. 15, 2018, 2:46 p.m. UTC | #1
> 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@ovn.org>
> Signed-off-by: Aaron Conole <aconole@bytheb.org>

Thanks for this Aaron, fixes the travis CI build also.

Acked-by: Ian Stokes <ian.stokes@intel.com>
Tested-by: Ian Stokes <ian.stokes@intel.com>

> ---
>  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)),
> --
> 2.14.3
> 
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
Ben Pfaff Jan. 15, 2018, 7:24 p.m. UTC | #2
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@ovn.org>
> Signed-off-by: Aaron Conole <aconole@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.
Aaron Conole Jan. 15, 2018, 7:55 p.m. UTC | #3
Ben Pfaff <blp@ovn.org> writes:

> 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@ovn.org>
>> Signed-off-by: Aaron Conole <aconole@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).

Okay, I will resubmit.  Thanks, Ben!

> Thanks,
>
> Ben.
diff mbox series

Patch

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)),