Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf list: Don't write to const memory

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 strchrnul() + strncmp() instead of temporarily scrubbing
it with '\0'.

Reviewed-by: Ian Rogers <irogers@google.com>
Suggested-by: David Laight <david.laight.linux@gmail.com>
Link: https://lore.kernel.org/r/20260121112536.27fd5d11@pumpkin
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+2 -7
+2 -7
tools/perf/util/print-events.c
··· 97 97 } else { 98 98 next_sdt_name = strlist__next(sdt_name); 99 99 if (next_sdt_name) { 100 - char *bid2 = strchr(next_sdt_name->s, '@'); 100 + const char *bid2 = strchrnul(next_sdt_name->s, '@'); 101 101 102 - if (bid2) 103 - *bid2 = '\0'; 104 - if (strcmp(sdt_name->s, next_sdt_name->s) == 0) 105 - show_detail = true; 106 - if (bid2) 107 - *bid2 = '@'; 102 + show_detail = strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0; 108 103 } 109 104 } 110 105 last_sdt_name = sdt_name->s;