All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/1] swapping01: fix parameter truncation in abs
@ 2021-01-15 12:25 Alexander Egorenkov
  2021-01-20 11:11 ` Petr Vorel
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Egorenkov @ 2021-01-15 12:25 UTC (permalink / raw)
  To: ltp

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

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++;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [LTP] [PATCH 1/1] swapping01: fix parameter truncation in abs
  2021-01-15 12:25 [LTP] [PATCH 1/1] swapping01: fix parameter truncation in abs Alexander Egorenkov
@ 2021-01-20 11:11 ` Petr Vorel
  0 siblings, 0 replies; 2+ messages in thread
From: Petr Vorel @ 2021-01-20 11:11 UTC (permalink / raw)
  To: ltp

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-20 11:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-15 12:25 [LTP] [PATCH 1/1] swapping01: fix parameter truncation in abs Alexander Egorenkov
2021-01-20 11:11 ` Petr Vorel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.