[dpdk-dev] [PATCH] app/testpmd: fix division by zero bug

Min Hu (Connor) humin29 at huawei.com
Wed Apr 21 13:38:22 CEST 2021


Variable total, which may be zero and result in segmentation fault.

This patch fixed it.

Fixes: 9b1249d9ff69 ("app/testpmd: support dumping socket memory")
Cc: stable at dpdk.org

Signed-off-by: Min Hu (Connor) <humin29 at huawei.com>
---
 app/test-pmd/cmdline.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 08da2b1..cde0a00 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -9631,6 +9631,9 @@ dump_socket_mem(FILE *f)
 			socket_stats.alloc_count,
 			socket_stats.free_count);
 	}
+
+	if (total == 0)
+		return;
 	fprintf(f,
 		"Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
 		(double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
-- 
2.7.4



More information about the dev mailing list