diff mbox series

[iproute2,5/5] ifstat: fix warning about conditional

Message ID 20230628233813.6564-6-stephen@networkplumber.org (mailing list archive)
State Accepted
Commit bbfccc11e1c4399f46921365b36807c3791be536
Delegated to: David Ahern
Headers show
Series Warning fixes | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Stephen Hemminger June 28, 2023, 11:38 p.m. UTC
Gcc with warnings enabled complains because the conditional.
  if ((long)(a - b) < 0)
could be construed as never true.  Change to simple comparison.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 misc/ifstat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Petr Machata June 29, 2023, 1:49 p.m. UTC | #1
Stephen Hemminger <stephen@networkplumber.org> writes:

> Gcc with warnings enabled complains because the conditional.
>   if ((long)(a - b) < 0)
> could be construed as never true.

Hmm, yeah, it would never be true where sizeof(long) > 4.

>                                    Change to simple comparison.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

Reviewed-by: Petr Machata <me@pmachata.org>
diff mbox series

Patch

diff --git a/misc/ifstat.c b/misc/ifstat.c
index 4ce5ca8af4e7..f6f9ba5027d3 100644
--- a/misc/ifstat.c
+++ b/misc/ifstat.c
@@ -608,7 +608,7 @@  static void update_db(int interval)
 				int i;
 
 				for (i = 0; i < MAXS; i++) {
-					if ((long)(h1->ival[i] - n->ival[i]) < 0) {
+					if (h1->ival[i] < n->ival[i]) {
 						memset(n->ival, 0, sizeof(n->ival));
 						break;
 					}