[binutils-gdb] RISC-V: avoid strdup()

Jan Beulich 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=433560c5807319762b57e3cc323cc5521d6efe9e

commit 433560c5807319762b57e3cc323cc5521d6efe9e
Author: Jan Beulich <[email protected]>
Date:   Fri May 15 09:46:55 2026 +0200

    RISC-V: avoid strdup()
    
    Along with xmalloc(), xstrdup() wants using.
    
    Reviewed-by: Jiawei <[email protected]>

Diff:
---
 bfd/elfxx-riscv.c     | 2 +-
 gas/config/tc-riscv.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
index 341527b752f..030f27da5d9 100644
--- a/bfd/elfxx-riscv.c
+++ b/bfd/elfxx-riscv.c
@@ -2589,7 +2589,7 @@ riscv_copy_subset_list (riscv_subset_list_t *subset_list)
 {
   riscv_subset_list_t *new = xmalloc (sizeof *new);
   new->head = riscv_copy_subset (new, subset_list->head);
-  new->arch_str = strdup (subset_list->arch_str);
+  new->arch_str = xstrdup (subset_list->arch_str);
   return new;
 }
 
diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index b00b530b0bd..7337ad07d8d 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -358,7 +358,7 @@ riscv_set_arch (const char *s)
   riscv_release_subset_list (riscv_rps_as.subset_list);
   riscv_parse_subset (&riscv_rps_as, s);
   riscv_arch_str (xlen, riscv_rps_as.subset_list, true/* update */);
-  file_arch_str = strdup (riscv_rps_as.subset_list->arch_str);
+  file_arch_str = xstrdup (riscv_rps_as.subset_list->arch_str);
 
   riscv_set_rvc (riscv_subset_supports (&riscv_rps_as, "c")
 		 || riscv_subset_supports (&riscv_rps_as, "zca"));
@@ -1435,7 +1435,7 @@ static bool
 reglist_lookup (char **s, unsigned *reg_list)
 {
   *reg_list = 0;
-  char *reglist = strdup (*s);
+  char *reglist = xstrdup (*s);
   if (reglist != NULL)
     {
       char *token = strtok (reglist, "}");
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.