[1/2] gprof: Fix strchr discarded qualifier call
Checks
Commit Message
In annotate_source strrchr is called on a const char *. So the result
should also be stored in a const char *.
* gprof/source.c (annotate_source): Make name_only a const char *.
---
gprof/source.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On Sun, May 3, 2026 at 1:02 AM Mark Wielaard <mark@klomp.org> wrote:
>
> In annotate_source strrchr is called on a const char *. So the result
> should also be stored in a const char *.
>
> * gprof/source.c (annotate_source): Make name_only a const char *.
> ---
> gprof/source.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/gprof/source.c b/gprof/source.c
> index 494f6ecc9b20..aae55f6d758f 100644
> --- a/gprof/source.c
> +++ b/gprof/source.c
> @@ -98,7 +98,8 @@ annotate_source (Source_File *sf, unsigned int max_width,
> bool new_line;
> char buf[8192];
> char *fname;
> - char *annotation, *name_only;
> + char *annotation;
> + const char *name_only;
> FILE *ifp, *ofp;
> Search_List_Elem *sle = src_search_list.head;
>
> --
> 2.54.0
>
We should combine this strrchr patch set with the patch set from
Calvin Owens <calvin@wbinvd.org>:
https://patchwork.sourceware.org/project/binutils/list/?series=60290
On Sun, May 3, 2026 at 6:52 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Sun, May 3, 2026 at 1:02 AM Mark Wielaard <mark@klomp.org> wrote:
> >
> > In annotate_source strrchr is called on a const char *. So the result
> > should also be stored in a const char *.
> >
> > * gprof/source.c (annotate_source): Make name_only a const char *.
> > ---
> > gprof/source.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/gprof/source.c b/gprof/source.c
> > index 494f6ecc9b20..aae55f6d758f 100644
> > --- a/gprof/source.c
> > +++ b/gprof/source.c
> > @@ -98,7 +98,8 @@ annotate_source (Source_File *sf, unsigned int max_width,
> > bool new_line;
> > char buf[8192];
> > char *fname;
> > - char *annotation, *name_only;
> > + char *annotation;
> > + const char *name_only;
> > FILE *ifp, *ofp;
> > Search_List_Elem *sle = src_search_list.head;
> >
> > --
> > 2.54.0
> >
>
> We should combine this strrchr patch set with the patch set from
> Calvin Owens <calvin@wbinvd.org>:
>
> https://patchwork.sourceware.org/project/binutils/list/?series=60290
>
Calvin's patch has been checked in. Here is another one for DOS based
filesystem:
Fix the strrchr error like:
gprof/source.c:130:28: error: initialization discards ‘const’
qualifier from pointer target type [-Werror=discarded-qualifiers]
130 | char *bslash = strrchr (sf->name, '\\');
binutils/
* bucomm.c (template_in_dir): Make bslash const char *.
gprof/
* source.c (annotate_source): Make bslash const char *.
On Sun, May 03, 2026 at 08:32:51AM +0800, H.J. Lu wrote:
> Calvin's patch has been checked in. Here is another one for DOS based
> filesystem:
Well, one of them was.
> Fix the strrchr error like:
>
> gprof/source.c:130:28: error: initialization discards ‘const’
> qualifier from pointer target type [-Werror=discarded-qualifiers]
> 130 | char *bslash = strrchr (sf->name, '\\');
>
> binutils/
>
> * bucomm.c (template_in_dir): Make bslash const char *.
>
> gprof/
>
> * source.c (annotate_source): Make bslash const char *.
Please commit.
On Sun, May 3, 2026 at 1:02 AM Mark Wielaard <mark@klomp.org> wrote:
>
> In annotate_source strrchr is called on a const char *. So the result
> should also be stored in a const char *.
>
> * gprof/source.c (annotate_source): Make name_only a const char *.
> ---
> gprof/source.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/gprof/source.c b/gprof/source.c
> index 494f6ecc9b20..aae55f6d758f 100644
> --- a/gprof/source.c
> +++ b/gprof/source.c
> @@ -98,7 +98,8 @@ annotate_source (Source_File *sf, unsigned int max_width,
> bool new_line;
> char buf[8192];
> char *fname;
> - char *annotation, *name_only;
> + char *annotation;
> + const char *name_only;
> FILE *ifp, *ofp;
> Search_List_Elem *sle = src_search_list.head;
>
> --
> 2.54.0
>
I think this counts an obvious fix.
@@ -98,7 +98,8 @@ annotate_source (Source_File *sf, unsigned int max_width,
bool new_line;
char buf[8192];
char *fname;
- char *annotation, *name_only;
+ char *annotation;
+ const char *name_only;
FILE *ifp, *ofp;
Search_List_Elem *sle = src_search_list.head;