[binutils-gdb] Fix the strrchr error for DOS based filesystem

"H.J. Lu via Binutils-cvs" <[email protected]>
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=365fc34606d2d566855e8ba3db9c4f7986ed3bcc

commit 365fc34606d2d566855e8ba3db9c4f7986ed3bcc
Author: H.J. Lu <[email protected]>
Date:   Sun May 3 08:25:28 2026 +0800

    Fix the strrchr error 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 *.
    
    Signed-off-by: H.J. Lu <[email protected]>

Diff:
---
 binutils/bucomm.c | 2 +-
 gprof/source.c    | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/binutils/bucomm.c b/binutils/bucomm.c
index 14a0db22425..da704bcf838 100644
--- a/binutils/bucomm.c
+++ b/binutils/bucomm.c
@@ -502,7 +502,7 @@ template_in_dir (const char *path)
 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
   {
     /* We could have foo/bar\\baz, or foo\\bar, or d:bar.  */
-    char *bslash = strrchr (path, '\\');
+    const char *bslash = strrchr (path, '\\');
 
     if (slash == NULL || (bslash != NULL && bslash > slash))
       slash = bslash;
diff --git a/gprof/source.c b/gprof/source.c
index 494f6ecc9b2..860c0b5fec0 100644
--- a/gprof/source.c
+++ b/gprof/source.c
@@ -126,7 +126,7 @@ annotate_source (Source_File *sf, unsigned int max_width,
 	  name_only = strrchr (sf->name, '/');
 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
 	  {
-	    char *bslash = strrchr (sf->name, '\\');
+	    const char *bslash = strrchr (sf->name, '\\');
 	    if (name_only == NULL || (bslash != NULL && bslash > name_only))
 	      name_only = bslash;
 	    if (name_only == NULL && sf->name[0] != '\0' && sf->name[1] == ':')
@@ -183,7 +183,7 @@ annotate_source (Source_File *sf, unsigned int max_width,
       filename = strrchr (sf->name, '/');
 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
 	{
-	  char *bslash = strrchr (sf->name, '\\');
+	  const char *bslash = strrchr (sf->name, '\\');
 	  if (filename == NULL || (bslash != NULL && bslash > filename))
 	    filename = bslash;
 	  if (filename == NULL && sf->name[0] != '\0' && sf->name[1] == ':')
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.