From d89af9acb7283f8f446c976a0f3f425424768d1e Mon Sep 17 00:00:00 2001 From: Joseph Hwang Date: Wed, 16 Feb 2022 16:15:18 +0800 Subject: [PATCH] monitor: fix division by zero about conn->tx_pkt_med In a connection without outgoing traffic, conn->tx_num will remain 0. In this case, conn->tx_pkt_med should be simply 0 without calculating "conn->tx_bytes / conn->tx_num". This was likely to happen, for example, when "btmon -w btsnoop.log" was launched in the middle of a LE mouse connection, and a number of incoming ACL Data RX were received as the mouse movements. When running "btmon -a btsnoop.log", it would encounter this error. Reviewed-by: Alain Michaud Reviewed-by: Yun-Hao Chung Reviewed-by: Shuo-Peng Liao --- monitor/analyze.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/monitor/analyze.c b/monitor/analyze.c index 0c74e8f2e..ac23e13bb 100644 --- a/monitor/analyze.c +++ b/monitor/analyze.c @@ -161,7 +161,8 @@ static void conn_destroy(void *data) break; } - conn->tx_pkt_med = conn->tx_bytes / conn->tx_num; + if (conn->tx_num > 0) + conn->tx_pkt_med = conn->tx_bytes / conn->tx_num; printf(" Found %s connection with handle %u\n", str, conn->handle); /* TODO: Store address type */ -- 2.47.3