[PATCH 2/2] perf hist: Refine signed integer checking
From: Leo Yan
Date: Fri Mar 28 2025 - 08:27:22 EST
To avoid any issues caused by overflow in a signed integer, and since
the limit to USHRT_MAX is not necessary, this patch simply decrements
the signed integer and checks that it is greater than 0.
Signed-off-by: Leo Yan <leo.yan@xxxxxxx>
---
tools/perf/ui/stdio/hist.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 7ac4b98e28bc..6da624309fab 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: GPL-2.0
-#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <linux/string.h>
@@ -25,10 +24,7 @@ static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
int i;
int ret = fprintf(fp, " ");
- if (left_margin > USHRT_MAX)
- left_margin = USHRT_MAX;
-
- for (i = 0; i < left_margin; i++)
+ for (i = left_margin; i > 0; i--)
ret += fprintf(fp, " ");
return ret;
--
2.34.1