diff options
| author | Zhaoqi Xu <[email protected]> | 2026-10-06 14:07:59 +0800 |
|---|---|---|
| committer | Rbb666 <[email protected]> | 2026-10-14 09:33:19 +0800 |
| commit | 8ec9d87959fe27682e02ced7158012d8fb0048c1 (patch) | |
| tree | eff186bf965119027d291d00560fb988d6b4279b /components/net/netdev/src/netdev.c | |
| parent | 517eecbe4a84755b76d8a11e5b00851a1048c1aa (diff) | |
[components][netdev] fix divide-by-zero in ping statistics when no reply
netdev_cmd_ping() computed avg_time / received before checking that any
reply arrived. When every request times out, received is 0 and the
integer division traps (SIGFPE on the simulator, a fault on Cortex-M),
taking the shell thread down. Only compute the average inside the
existing received > 0 branch where it is printed.
Fixes #11852
Diffstat (limited to 'components/net/netdev/src/netdev.c')
| -rw-r--r-- | components/net/netdev/src/netdev.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/components/net/netdev/src/netdev.c b/components/net/netdev/src/netdev.c index 5a4056b97a..b57e844504 100644 --- a/components/net/netdev/src/netdev.c +++ b/components/net/netdev/src/netdev.c @@ -1425,12 +1425,12 @@ int netdev_cmd_ping(char* target_name, char *netdev_name, rt_uint32_t times, rt_ /* print ping statistics */ loss = (uint32_t)((1 - ((float)received) / index) * 100); - avg_time = (uint32_t)(avg_time / received); rt_kprintf("\n--- %s ping statistics ---\n", inet_ntoa(ping_resp.ip_addr)); rt_kprintf("%d packets transmitted, %d received, %d%% packet loss\n", index, received, loss); if (received > 0) { + avg_time = (uint32_t)(avg_time / received); rt_kprintf("minimum = %dms, maximum = %dms, average = %dms\n", min_time, max_time, avg_time); } |
