Skip to content

Commit bc29e06

Browse files
acmelgregkh
authored andcommitted
perf diff: Constify strchr() return variables
commit f6f41ae upstream. Newer glibc versions return const char for strchr() when the 's' arg is const, change the return variable to const to match that. Also we don't need to turn that ',' into a '\0', as strtol() will stop in the first invalid char. No need to touch read only memory. First noticed with fedora 44. Reviewed-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/r/20251211221756.96294-3-acme@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 292f325 commit bc29e06

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

tools/perf/builtin-diff.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,9 @@ static struct header_column {
178178
}
179179
};
180180

181-
static int setup_compute_opt_wdiff(char *opt)
181+
static int setup_compute_opt_wdiff(const char *opt)
182182
{
183-
char *w1_str = opt;
184-
char *w2_str;
183+
const char *w1_str = opt, *w2_str;
185184

186185
int ret = -EINVAL;
187186

@@ -192,8 +191,7 @@ static int setup_compute_opt_wdiff(char *opt)
192191
if (!w2_str)
193192
goto out;
194193

195-
*w2_str++ = 0x0;
196-
if (!*w2_str)
194+
if (!*++w2_str)
197195
goto out;
198196

199197
compute_wdiff_w1 = strtol(w1_str, NULL, 10);
@@ -214,7 +212,7 @@ static int setup_compute_opt_wdiff(char *opt)
214212
return ret;
215213
}
216214

217-
static int setup_compute_opt(char *opt)
215+
static int setup_compute_opt(const char *opt)
218216
{
219217
if (compute == COMPUTE_WEIGHTED_DIFF)
220218
return setup_compute_opt_wdiff(opt);
@@ -234,7 +232,7 @@ static int setup_compute(const struct option *opt, const char *str,
234232
char *cstr = (char *) str;
235233
char buf[50];
236234
unsigned i;
237-
char *option;
235+
const char *option;
238236

239237
if (!str) {
240238
*cp = COMPUTE_DELTA;

0 commit comments

Comments
 (0)