Re: [PATCH] pahole: fix discarded-qualifiers for strchr/strstr
Alan Maguire <[email protected]>
| Newsgroups | org.kernel.vger.dwarves |
|---|---|
| Message-ID | <[email protected]> |
On 04/03/2026 03:06, damien hourtoulle wrote: > From fa4866e368f5131ddcf6fddccc13203fab88d00d Mon Sep 17 00:00:00 2001 > From: Damien Hourtoulle <[email protected]> > Date: Wed, 4 Mar 2026 03:30:31 +0100 > Subject: [PATCH] pahole: fix discarded-qualifiers for strchr/strstr. > > Glibc 2.43 added C23 const-preserving overloads : > https://sourceware.org/glibc/wiki/Release/2.43. > > For the function prototype__new, fix local variable declaration to use > the correct const char* type instead of char*, removing the need to > discard > the const qualifier. > > Signed-off-by: Damien Hourtoulle <[email protected]> hi, there are a few issues below I think.. > --- > btf_encoder.c | 2 +- > pahole.c | 19 +++++++++---------- > 2 files changed, 10 insertions(+), 11 deletions(-) > > diff --git a/btf_encoder.c b/btf_encoder.c > index aa7cd1c..d36984a 100644 > --- a/btf_encoder.c > +++ b/btf_encoder.c > @@ -1218,7 +1218,7 @@ static bool str_contains_non_fn_suffix(const char *str) { > ".cold", > ".part" > }; > - char *suffix = strchr(str, '.'); > + const char *suffix = strchr(str, '.'); > int i; > > if (!suffix) > diff --git a/pahole.c b/pahole.c > index 02a0d19..4184703 100644 > --- a/pahole.c > +++ b/pahole.c > @@ -2483,7 +2483,7 @@ static int64_t type_instance__int_value(struct > type_instance *instance, const ch > int byte_offset = 0; > > if (!member) { > - char *sep = strchr(member_name_orig, '.'); > + const char *sep = strchr(member_name_orig, '.'); > > if (!sep) > return -1; > @@ -2496,8 +2496,8 @@ static int64_t type_instance__int_value(struct > type_instance *instance, const ch > char *member_name = member_name_alloc; > struct type *type = instance->type; > > - sep = member_name_alloc + (sep - member_name_orig); > - *sep = 0; > + char *sep_mutable = member_name_alloc + (sep - > member_name_orig); // sep mutable for the copy > + *sep_mutable = 0; > > while (1) { > member = type__find_member_by_name(type, member_name); > @@ -2510,7 +2510,7 @@ out_free_member_name: > type = tag__type(cu__type(cu, member->tag.type)); > if (type == NULL) > goto out_free_member_name; > - member_name = sep + 1; > + member_name = sep_mutable + 1; > sep = strchr(member_name, '.'); I think this should be sep_mutable = strchr(member_name, '.'); > if (!sep) > break; > @@ -2950,7 +2950,7 @@ static struct prototype *prototype__new(const > char *expression) > > strcpy(prototype->name, expression); > > - const char *name = prototype->name; > + char *name = prototype->name; > > prototype->nr_args = 0; > > @@ -2964,10 +2964,9 @@ static struct prototype *prototype__new(const > char *expression) > if (args_close == NULL) > goto out_no_closing_parens; > > + *args_open++ = *args_close = '\0'; > char *args = args_open; > > - *args++ = *args_close = '\0'; > - > while (isspace(*args)) > ++args; > > @@ -3114,7 +3113,7 @@ static int type__find_type_enum(struct type > *type, struct cu *cu, const char *ty > return type__add_type_enum(type, te, cu); > > // Now look at a 'virtual enum', i.e. the concatenation of > multiple enums > - char *sep = strchr(type_enum, '+'); > + const char *sep = strchr(type_enum, '+'); > > if (!sep) > return -1; > @@ -3126,10 +3125,10 @@ static int type__find_type_enum(struct type > *type, struct cu *cu, const char *ty > > int ret = -1; > > - sep = type_enums + (sep - type_enum); > + char *sep_mutable = type_enums + (sep - type_enum); > > type_enum = type_enums; > - *sep = '\0'; > + *sep_mutable = '\0'; > > while (1) { > te = cu__find_enumeration_by_name(cu, type_enum, NULL); there's a similar issue in the loop here not visible in patch diffs I think; the loop now updates sep whereas it should update sep_mutable.