From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 111968 invoked by alias); 2 Apr 2016 18:43:20 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 111950 invoked by uid 89); 2 Apr 2016 18:43:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=s_is_defined, s_get_name, S_GET_NAME, S_IS_DEFINED X-HELO: paperclip.tbsaunde.org Received: from tbsaunde.org (HELO paperclip.tbsaunde.org) (66.228.47.254) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 02 Apr 2016 18:43:09 +0000 Received: from keg.corp.tor1.mozilla.com (unknown [66.207.193.21]) by paperclip.tbsaunde.org (Postfix) with ESMTPSA id DEFB6C06B; Sat, 2 Apr 2016 18:43:07 +0000 (UTC) From: tbsaunde+binutils@tbsaunde.org To: binutils@sourceware.org Cc: Trevor Saunders Subject: [PATCH] use xstrdup and friends more Date: Sat, 02 Apr 2016 18:43:00 -0000 Message-Id: <1459622896-7026-1-git-send-email-tbsaunde+binutils@tbsaunde.org> X-IsSubscribed: yes X-SW-Source: 2016-04/txt/msg00017.txt.bz2 From: Trevor Saunders Hi, $subject, its a lot simpler. built crosses and regtested ppc-elf, tic30-none-coff, and tic4x-coff, ok? Trev gas/ChangeLog: 2016-04-02 Trevor Saunders * config/obj-elf.c (obj_elf_vendor_attribute): Use xstrdup. * config/tc-ppc.c (ppc_frob_file_before_adjust): Likewise. (ppc_znop): Likewise. (ppc_pe_section): Likewise. (ppc_frob_symbol): Likewise. * config/tc-tic30.c (tic30_operand): Likewise. * config/tc-tic4x.c (tic4x_sect): Likewise. (tic4x_usect): Likewise. --- gas/config/obj-elf.c | 4 +--- gas/config/tc-ppc.c | 16 ++++------------ gas/config/tc-tic30.c | 8 ++------ gas/config/tc-tic4x.c | 6 ++---- 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c index 1d07d4b..68290e2 100644 --- a/gas/config/obj-elf.c +++ b/gas/config/obj-elf.c @@ -1609,9 +1609,7 @@ obj_elf_vendor_attribute (int vendor) if (i == 0) goto bad; - name = xmalloc (i + 1); - memcpy (name, s, i); - name[i] = '\0'; + name = xstrndup (s, i); #ifndef CONVERT_SYMBOLIC_ATTRIBUTE #define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1 diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c index cf4f96e..23a84a7 100644 --- a/gas/config/tc-ppc.c +++ b/gas/config/tc-ppc.c @@ -2390,7 +2390,6 @@ ppc_frob_file_before_adjust (void) const char *name; char *dotname; symbolS *dotsym; - size_t len; name = S_GET_NAME (symp); if (name[0] == '.') @@ -2400,10 +2399,7 @@ ppc_frob_file_before_adjust (void) || S_IS_DEFINED (symp)) continue; - len = strlen (name) + 1; - dotname = xmalloc (len + 1); - dotname[0] = '.'; - memcpy (dotname + 1, name, len); + dotname = concat (".", name, (char *) NULL); dotsym = symbol_find_noref (dotname, 1); free (dotname); if (dotsym != NULL && (symbol_used_p (dotsym) @@ -5195,8 +5191,7 @@ ppc_znop (int ignore ATTRIBUTE_UNUSED) /* Strip out the symbol name. */ c = get_symbol_name (&symbol_name); - name = xmalloc (input_line_pointer - symbol_name + 1); - strcpy (name, symbol_name); + name = xstrdup (symbol_name); sym = symbol_find_or_make (name); @@ -5370,8 +5365,7 @@ ppc_pe_section (int ignore ATTRIBUTE_UNUSED) c = get_symbol_name (§ion_name); - name = xmalloc (input_line_pointer - section_name + 1); - strcpy (name, section_name); + name = xstrdup (section_name); *input_line_pointer = c; @@ -5768,9 +5762,7 @@ ppc_frob_symbol (symbolS *sym) char *snew; len = s - name; - snew = xmalloc (len + 1); - memcpy (snew, name, len); - snew[len] = '\0'; + snew = xstrndup (name, len); S_SET_NAME (sym, snew); } diff --git a/gas/config/tc-tic30.c b/gas/config/tc-tic30.c index 71c6249..10653ed 100644 --- a/gas/config/tc-tic30.c +++ b/gas/config/tc-tic30.c @@ -604,9 +604,7 @@ tic30_operand (char *token) segT retval; debug ("Probably a label: %s\n", token); - current_op->immediate.label = malloc (strlen (token) + 1); - strcpy (current_op->immediate.label, token); - current_op->immediate.label[strlen (token)] = '\0'; + current_op->immediate.label = xstrdup (token); save_input_line_pointer = input_line_pointer; input_line_pointer = token; @@ -634,9 +632,7 @@ tic30_operand (char *token) for (count = 0; count < strlen (token); count++) if (*(token + count) == '.') current_op->immediate.decimal_found = 1; - current_op->immediate.label = malloc (strlen (token) + 1); - strcpy (current_op->immediate.label, token); - current_op->immediate.label[strlen (token)] = '\0'; + current_op->immediate.label = xstrdup (token); current_op->immediate.f_number = (float) atof (token); current_op->immediate.s_number = (int) atoi (token); current_op->immediate.u_number = (unsigned int) atoi (token); diff --git a/gas/config/tc-tic4x.c b/gas/config/tc-tic4x.c index c44201d..ba0aa38 100644 --- a/gas/config/tc-tic4x.c +++ b/gas/config/tc-tic4x.c @@ -964,8 +964,7 @@ tic4x_sect (int x ATTRIBUTE_UNUSED) if (c == '"') c = * ++ input_line_pointer; input_line_pointer++; /* Skip null symbol terminator. */ - name = xmalloc (input_line_pointer - section_name + 1); - strcpy (name, section_name); + name = xstrdup (section_name); /* TI C from version 5.0 allows a section name to contain a subsection name as well. The subsection name is separated by a @@ -1075,8 +1074,7 @@ tic4x_usect (int x ATTRIBUTE_UNUSED) if (c == '"') c = * ++ input_line_pointer; input_line_pointer++; /* Skip null symbol terminator. */ - name = xmalloc (input_line_pointer - section_name + 1); - strcpy (name, section_name); + name = xstrdup (section_name); if (c == ',') input_line_pointer = -- 2.1.4