]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf list: Don't write to const memory
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 20 Jan 2026 21:16:09 +0000 (18:16 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 21 Jan 2026 14:01:22 +0000 (11:01 -0300)
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>
tools/perf/util/print-events.c

index 4bbcdbf05b84330221bd64c3e051f6b2d31b808d..cb27e2898aa0558f813af2c6838561a86b4ed5e4 100644 (file)
@@ -97,14 +97,9 @@ 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 = strchrnul(next_sdt_name->s, '@');
+
+                               show_detail = strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0;
                        }
                }
                last_sdt_name = sdt_name->s;