diff mbox series

[1/1] swapping01: fix parameter truncation in abs

Message ID 20210115122543.288948-1-egorenar@linux.ibm.com
State Accepted
Headers show
Series [1/1] swapping01: fix parameter truncation in abs | expand

Commit Message

Alexander Egorenkov Jan. 15, 2021, 12:25 p.m. UTC
Parameters passed to abs(int) are of type long. Use labs(long) instead
to avoid value truncation.

Fixes the following warning:

swapping01.c: In function ‘check_swapping’:
swapping01.c:133:7: warning: absolute value function ‘abs’ given an argument of type ‘long int’ but has parameter of type ‘int’ which may cause truncation of value [-Wabsolute-value]
  133 |   if (abs(swap_free_now - SAFE_READ_MEMINFO("SwapFree:")) < 512)
      |       ^~~

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
---
 testcases/kernel/mem/swapping/swapping01.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Petr Vorel Jan. 20, 2021, 11:11 a.m. UTC | #1
Hi Alexander,

> Parameters passed to abs(int) are of type long. Use labs(long) instead
> to avoid value truncation.

> Fixes the following warning:

> swapping01.c: In function ‘check_swapping’:
> swapping01.c:133:7: warning: absolute value function ‘abs’ given an argument of type ‘long int’ but has parameter of type ‘int’ which may cause truncation of value [-Wabsolute-value]
>   133 |   if (abs(swap_free_now - SAFE_READ_MEMINFO("SwapFree:")) < 512)
>       |       ^~~

Merged this obvious fix. Thanks!

Kind regards,
Petr
diff mbox series

Patch

diff --git a/testcases/kernel/mem/swapping/swapping01.c b/testcases/kernel/mem/swapping/swapping01.c
index ff40c85c0..24b8313f3 100644
--- a/testcases/kernel/mem/swapping/swapping01.c
+++ b/testcases/kernel/mem/swapping/swapping01.c
@@ -130,7 +130,7 @@  static void check_swapping(void)
 	while (i < 10) {
 		swap_free_now = SAFE_READ_MEMINFO("SwapFree:");
 		sleep(1);
-		if (abs(swap_free_now - SAFE_READ_MEMINFO("SwapFree:")) < 512)
+		if (labs(swap_free_now - SAFE_READ_MEMINFO("SwapFree:")) < 512)
 			break;
 
 		i++;