diff mbox series

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

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

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/checkpatch warning [BlueZ,2/2] core: Fix signed vs unsigned compare WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #89: FILE: src/device.c:4091: + if ((unsigned)now.tv_sec >= device->name_resolve_failed_time + /github/workspace/src/12900652.patch total: 0 errors, 1 warnings, 8 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /github/workspace/src/12900652.patch has style problems, please review. NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
tedd_an/gitlint fail [BlueZ,2/2] core: Fix signed vs unsigned compare 9: B1 Line exceeds max length (162>80): "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]"

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;