From: Leo Yan <leo.yan@arm.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Ian Rogers <irogers@google.com>, Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
"Liang, Kan" <kan.liang@linux.intel.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Leo Yan <leo.yan@arm.com>
Subject: [PATCH 2/2] perf hist: Refine signed integer checking
Date: Fri, 28 Mar 2025 12:26:44 +0000 [thread overview]
Message-ID: <20250328122644.2383698-3-leo.yan@arm.com> (raw)
In-Reply-To: <20250328122644.2383698-1-leo.yan@arm.com>
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@arm.com>
---
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
prev parent reply other threads:[~2025-03-28 12:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-28 12:26 [PATCH 0/2] perf build: Minor cleanup Leo Yan
2025-03-28 12:26 ` [PATCH 1/2] perf build: Remove unused LIBPERF_CLFAGS Leo Yan
2025-03-28 16:30 ` Ian Rogers
[not found] ` <CA+JHD90hqsAQn8FcwdBnzU8aPOmey76MrUkGitu9E4i2sC2bWw@mail.gmail.com>
2025-03-28 17:16 ` Leo Yan
2025-03-28 12:26 ` Leo Yan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250328122644.2383698-3-leo.yan@arm.com \
--to=leo.yan@arm.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®