lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 5 Nov 2021 13:44:06 -0700
From:   Nick Desaulniers <ndesaulniers@...gle.com>
To:     Anders Roxell <anders.roxell@...aro.org>
Cc:     shuah@...nel.org, tglx@...utronix.de, john.stultz@...aro.org,
        nathan@...nel.org, linux-kernel@...r.kernel.org,
        linux-kselftest@...r.kernel.org, llvm@...ts.linux.dev
Subject: Re: [PATCH] selftests: timers: use 'llabs()' over 'abs()'

On Fri, Nov 5, 2021 at 9:34 AM Anders Roxell <anders.roxell@...aro.org> wrote:
>
> When building selftests/timers with clang, the compiler warn about the
> function abs() see below:
>
> posix_timers.c:69:6: warning: absolute value function 'abs' given an argument of type 'long long' but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value]
>         if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) {
>             ^
> posix_timers.c:69:6: note: use function 'llabs' instead
>         if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) {
>             ^~~
>             llabs
>
> The note indicates what to do, Rework to use the function 'llabs()'.
>
> Signed-off-by: Anders Roxell <anders.roxell@...aro.org>

Thanks for the patch!
Reviewed-by: Nick Desaulniers <ndesaulniers@...gle.com>

I wonder why tools/testing/selftests/timers/adjtick.c redefines llabs
when it already includes stdlib.h, and how that doesn't result in some
kind of compiler diagnostic.

> ---
>  tools/testing/selftests/timers/posix_timers.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
> index 337424c5c987..73fb27901a1d 100644
> --- a/tools/testing/selftests/timers/posix_timers.c
> +++ b/tools/testing/selftests/timers/posix_timers.c
> @@ -66,7 +66,7 @@ static int check_diff(struct timeval start, struct timeval end)
>         diff = end.tv_usec - start.tv_usec;
>         diff += (end.tv_sec - start.tv_sec) * USECS_PER_SEC;
>
> -       if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) {
> +       if (llabs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) {
>                 printf("Diff too high: %lld..", diff);
>                 return -1;
>         }
> --
> 2.33.0
>


-- 
Thanks,
~Nick Desaulniers

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ