[PATCH 3/4] perf list: Don't write to const memory
From: Arnaldo Carvalho de Melo
Date: Tue Jan 20 2026 - 17:11:25 EST
From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Something now detected on fedora 44, where strchr() returns const if it
is passed a const pointer:
util/print-events.c: In function 'print_sdt_events':
util/print-events.c:89:29: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
89 | char *bid = strchr(sdt_name->s, '@');
| ^~~~~~
Fix it by using strnchr() if strchr finds the separator instead of
temporarily scrubbing it with '\0'.
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/print-events.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
index 8f3ed83853a9e468..898cf426509790cd 100644
--- a/tools/perf/util/print-events.c
+++ b/tools/perf/util/print-events.c
@@ -97,14 +97,11 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
} else {
next_sdt_name = strlist__next(sdt_name);
if (next_sdt_name) {
- char *bid2 = strchr(next_sdt_name->s, '@');
-
- if (bid2)
- *bid2 = '\0';
- if (strcmp(sdt_name->s, next_sdt_name->s) == 0)
- show_detail = true;
- if (bid2)
- *bid2 = '@';
+ const char *bid2 = strchr(next_sdt_name->s, '@');
+
+ show_detail = bid2 ?
+ strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0 :
+ strcmp(sdt_name->s, next_sdt_name->s) == 0;
}
}
last_sdt_name = sdt_name->s;
--
2.52.0