diff mbox series

[BlueZ,2/2] core: Fix signed vs unsigned compare

Message ID 20220629194432.20229-2-brian.gix@intel.com
State Superseded
Headers show
Series [BlueZ,1/2] core: make bt_uuid_hash() portable across archs | expand

Commit Message

Brian Gix June 29, 2022, 7:44 p.m. UTC
__time_t is not a portable data type, and can cause sign mismatch on
come compares.

Fixes:
  CC       src/bluetoothd-device.o
src/device.c: In function ‘device_is_name_resolve_allowed’:
src/device.c:4092:17: error: comparison of integer expressions of different signedness: ‘__time_t’ {aka ‘long int’} and ‘long unsigned int’ [-Werror=sign-compare]
  if (now.tv_sec >= device->name_resolve_failed_time +
                 ^~
cc1: all warnings being treated as errors
---
 src/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Luiz Augusto von Dentz June 29, 2022, 9:07 p.m. UTC | #1
Hi Brian,

On Wed, Jun 29, 2022 at 12:56 PM Brian Gix <brian.gix@intel.com> wrote:
>
> __time_t is not a portable data type, and can cause sign mismatch on
> come compares.
>
> Fixes:
>   CC       src/bluetoothd-device.o
> src/device.c: In function ‘device_is_name_resolve_allowed’:
> src/device.c:4092:17: error: comparison of integer expressions of different signedness: ‘__time_t’ {aka ‘long int’} and ‘long unsigned int’ [-Werror=sign-compare]
>   if (now.tv_sec >= device->name_resolve_failed_time +
>                  ^~
> cc1: all warnings being treated as errors
> ---
>  src/device.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/device.c b/src/device.c
> index 7b451e458..012d73583 100644
> --- a/src/device.c
> +++ b/src/device.c
> @@ -4088,7 +4088,7 @@ bool device_is_name_resolve_allowed(struct btd_device *device)
>         /* now >= failed_time + name_request_retry_delay, meaning the
>          * period of not sending name request is over.
>          */
> -       if (now.tv_sec >= device->name_resolve_failed_time +
> +       if ((unsigned)now.tv_sec >= device->name_resolve_failed_time +
>                                         btd_opts.name_request_retry_delay)
>                 return true;
>
> --
> 2.36.1

Can't we just use the same type for name_resolve_failed_time?
diff mbox series

Patch

diff --git a/src/device.c b/src/device.c
index 7b451e458..012d73583 100644
--- a/src/device.c
+++ b/src/device.c
@@ -4088,7 +4088,7 @@  bool device_is_name_resolve_allowed(struct btd_device *device)
 	/* now >= failed_time + name_request_retry_delay, meaning the
 	 * period of not sending name request is over.
 	 */
-	if (now.tv_sec >= device->name_resolve_failed_time +
+	if ((unsigned)now.tv_sec >= device->name_resolve_failed_time +
 					btd_opts.name_request_retry_delay)
 		return true;