use xstrdup, xmemdup0 and concat more
authorTrevor Saunders <tbsaunde+binutils@tbsaunde.org>
Mon, 28 Mar 2016 09:49:15 +0000 (05:49 -0400)
committerTrevor Saunders <tbsaunde+binutils@tbsaunde.org>
Fri, 13 May 2016 04:35:51 +0000 (00:35 -0400)
gas/ChangeLog:

2016-05-13  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

* config/obj-coff.c (obj_coff_def): Simplify string copying.
(weak_name2altname): Likewise.
(weak_uniquify): Likewise.
(obj_coff_section): Likewise.
(obj_coff_init_stab_section): Likewise.
* config/obj-elf.c (obj_elf_section_name): Likewise.
(obj_elf_init_stab_section): Likewise.
* config/obj-evax.c (evax_shorten_name): Likewise.
* config/obj-macho.c (obj_mach_o_make_or_get_sect): Likewise.
* config/tc-aarch64.c (create_register_alias): Likewise.
* config/tc-alpha.c (load_expression): Likewise.
(s_alpha_file): Likewise.
(s_alpha_section_name): Likewise.
(tc_gen_reloc): Likewise.
* config/tc-arc.c (md_assemble): Likewise.
* config/tc-arm.c (create_neon_reg_alias): Likewise.
(start_unwind_section): Likewise.
* config/tc-hppa.c (pa_build_unwind_subspace): Likewise.
(hppa_elf_mark_end_of_function): Likewise.
* config/tc-nios2.c (nios2_modify_arg): Likewise.
(nios2_negate_arg): Likewise.
* config/tc-rx.c (rx_section): Likewise.
* config/tc-sh64.c (sh64_consume_datalabel): Likewise.
* config/tc-tic30.c (tic30_find_parallel_insn): Likewise.
* config/tc-tic54x.c (tic54x_include): Likewise.
(tic54x_macro_info): Likewise.
(subsym_get_arg): Likewise.
(subsym_substitute): Likewise.
(tic54x_start_line_hook): Likewise.
* config/tc-xtensa.c (xtensa_literal_prefix): Likewise.
(xg_reverse_shift_count): Likewise.
* config/xtensa-relax.c (enter_opname_n): Likewise.
(split_string): Likewise.
* dwarf2dbg.c (get_filenum): Likewise.
(process_entries): Likewise.
* expr.c (operand): Likewise.
* itbl-ops.c (alloc_entry): Likewise.
* listing.c (listing_message): Likewise.
(listing_title): Likewise.
* macro.c (check_macro): Likewise.
* stabs.c (s_xstab): Likewise.
* symbols.c (symbol_relc_make_expr): Likewise.
* write.c (compress_debug): Likewise.

26 files changed:
gas/ChangeLog
gas/as.h
gas/config/obj-coff.c
gas/config/obj-elf.c
gas/config/obj-evax.c
gas/config/obj-macho.c
gas/config/tc-aarch64.c
gas/config/tc-alpha.c
gas/config/tc-arc.c
gas/config/tc-arm.c
gas/config/tc-hppa.c
gas/config/tc-nios2.c
gas/config/tc-rx.c
gas/config/tc-sh64.c
gas/config/tc-tic30.c
gas/config/tc-tic54x.c
gas/config/tc-xtensa.c
gas/config/xtensa-relax.c
gas/dwarf2dbg.c
gas/expr.c
gas/itbl-ops.c
gas/listing.c
gas/macro.c
gas/stabs.c
gas/symbols.c
gas/write.c

index 47e63d899bfd07795aa9d52f91d0fa07216ae353..a3e6b3ec6ce1e1b43d7869f6a05ce852ba60306e 100644 (file)
@@ -1,3 +1,49 @@
+2016-05-13  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>
+
+       * config/obj-coff.c (obj_coff_def): Simplify string copying.
+       (weak_name2altname): Likewise.
+       (weak_uniquify): Likewise.
+       (obj_coff_section): Likewise.
+       (obj_coff_init_stab_section): Likewise.
+       * config/obj-elf.c (obj_elf_section_name): Likewise.
+       (obj_elf_init_stab_section): Likewise.
+       * config/obj-evax.c (evax_shorten_name): Likewise.
+       * config/obj-macho.c (obj_mach_o_make_or_get_sect): Likewise.
+       * config/tc-aarch64.c (create_register_alias): Likewise.
+       * config/tc-alpha.c (load_expression): Likewise.
+       (s_alpha_file): Likewise.
+       (s_alpha_section_name): Likewise.
+       (tc_gen_reloc): Likewise.
+       * config/tc-arc.c (md_assemble): Likewise.
+       * config/tc-arm.c (create_neon_reg_alias): Likewise.
+       (start_unwind_section): Likewise.
+       * config/tc-hppa.c (pa_build_unwind_subspace): Likewise.
+       (hppa_elf_mark_end_of_function): Likewise.
+       * config/tc-nios2.c (nios2_modify_arg): Likewise.
+       (nios2_negate_arg): Likewise.
+       * config/tc-rx.c (rx_section): Likewise.
+       * config/tc-sh64.c (sh64_consume_datalabel): Likewise.
+       * config/tc-tic30.c (tic30_find_parallel_insn): Likewise.
+       * config/tc-tic54x.c (tic54x_include): Likewise.
+       (tic54x_macro_info): Likewise.
+       (subsym_get_arg): Likewise.
+       (subsym_substitute): Likewise.
+       (tic54x_start_line_hook): Likewise.
+       * config/tc-xtensa.c (xtensa_literal_prefix): Likewise.
+       (xg_reverse_shift_count): Likewise.
+       * config/xtensa-relax.c (enter_opname_n): Likewise.
+       (split_string): Likewise.
+       * dwarf2dbg.c (get_filenum): Likewise.
+       (process_entries): Likewise.
+       * expr.c (operand): Likewise.
+       * itbl-ops.c (alloc_entry): Likewise.
+       * listing.c (listing_message): Likewise.
+       (listing_title): Likewise.
+       * macro.c (check_macro): Likewise.
+       * stabs.c (s_xstab): Likewise.
+       * symbols.c (symbol_relc_make_expr): Likewise.
+       * write.c (compress_debug): Likewise.
+
 2016-05-12  Nick Clifton  <nickc@redhat.com>
 
        PR target/20068
index f3e1cf0af82388154751333ec22fdffd43c199b1..51e16f11bf8f5aa03b73aa1f2293a8cfb6f4f187 100644 (file)
--- a/gas/as.h
+++ b/gas/as.h
@@ -507,12 +507,12 @@ segT   subseg_get (const char *, int);
 const char *remap_debug_filename (const char *);
 void add_debug_prefix_map (const char *);
 
-static inline void *
-xmemdup0 (const void *in, size_t len)
+static inline char *
+xmemdup0 (const char *in, size_t len)
 {
   char *out = (char *) xmalloc (len + 1);
   out[len] = 0;
-  return memcpy (out, in, len);
+  return (char *) memcpy (out, in, len);
 }
 
 struct expressionS;
index 03be65517151504f8e8f564a71b954557023a81c..059f1cc32071aea03053804ffce8144f4f290f21 100644 (file)
@@ -592,7 +592,6 @@ obj_coff_def (int what ATTRIBUTE_UNUSED)
   char name_end;               /* Char after the end of name.  */
   char *symbol_name;           /* Name of the debug symbol.  */
   char *symbol_name_copy;      /* Temporary copy of the name.  */
-  unsigned int symbol_name_length;
 
   if (def_symbol_in_progress != NULL)
     {
@@ -604,9 +603,7 @@ obj_coff_def (int what ATTRIBUTE_UNUSED)
   SKIP_WHITESPACES ();
 
   name_end = get_symbol_name (&symbol_name);
-  symbol_name_length = strlen (symbol_name);
-  symbol_name_copy = xmalloc (symbol_name_length + 1);
-  strcpy (symbol_name_copy, symbol_name);
+  symbol_name_copy = xstrdup (symbol_name);
 #ifdef tc_canonicalize_symbol_name
   symbol_name_copy = tc_canonicalize_symbol_name (symbol_name_copy);
 #endif
@@ -1083,11 +1080,7 @@ weak_is_altname (const char * name)
 static const char *
 weak_name2altname (const char * name)
 {
-  char *alt_name;
-
-  alt_name = xmalloc (sizeof (weak_altprefix) + strlen (name));
-  strcpy (alt_name, weak_altprefix);
-  return strcat (alt_name, name);
+  return concat (weak_altprefix, name, (char *) NULL);
 }
 
 /* Return the name of the weak symbol corresponding to an
@@ -1115,11 +1108,7 @@ weak_uniquify (const char * name)
 #endif
   gas_assert (weak_is_altname (name));
 
-  ret = xmalloc (strlen (name) + strlen (unique) + 2);
-  strcpy (ret, name);
-  strcat (ret, ".");
-  strcat (ret, unique);
-  return ret;
+  return concat (name, ".", unique, (char *) NULL);
 }
 
 void
@@ -1562,8 +1551,7 @@ obj_coff_section (int ignore ATTRIBUTE_UNUSED)
     }
 
   c = get_symbol_name (&section_name);
-  name = xmalloc (input_line_pointer - section_name + 1);
-  strcpy (name, section_name);
+  name = xmemdup0 (section_name, input_line_pointer - section_name);
   *input_line_pointer = c;
   SKIP_WHITESPACE_AFTER_NAME ();
 
@@ -1820,9 +1808,7 @@ obj_coff_init_stab_section (segT seg)
   /* Zero it out.  */
   memset (p, 0, 12);
   file = as_where ((unsigned int *) NULL);
-  stabstr_name = xmalloc (strlen (seg->name) + 4);
-  strcpy (stabstr_name, seg->name);
-  strcat (stabstr_name, "str");
+  stabstr_name = concat (seg->name, "str", (char *) NULL);
   stroff = get_stab_string_offset (file, stabstr_name);
   know (stroff == 1);
   md_number_to_chars (p, stroff, 4);
index ea9f7abda85b587c2d9fd688e3a82b55cc033cce..b7eb7c1d41e892e13bfffb0ffb044c1c33ea973c 100644 (file)
@@ -949,9 +949,7 @@ obj_elf_section_name (void)
          return NULL;
        }
 
-      name = (char *) xmalloc (end - input_line_pointer + 1);
-      memcpy (name, input_line_pointer, end - input_line_pointer);
-      name[end - input_line_pointer] = '\0';
+      name = xmemdup0 (input_line_pointer, end - input_line_pointer);
 
       while (flag_sectname_subst)
         {
@@ -2060,9 +2058,7 @@ obj_elf_init_stab_section (segT seg)
   /* Zero it out.  */
   memset (p, 0, 12);
   file = as_where (NULL);
-  stabstr_name = (char *) xmalloc (strlen (segment_name (seg)) + 4);
-  strcpy (stabstr_name, segment_name (seg));
-  strcat (stabstr_name, "str");
+  stabstr_name = concat (segment_name (seg), "str", (char *) NULL);
   stroff = get_stab_string_offset (file, stabstr_name);
   know (stroff == 1 || (stroff == 0 && file[0] == '\0'));
   md_number_to_chars (p, stroff, 4);
index e36859209113637703b6e29d7435ed132334fa41..445828697a3a3a6e156d75d3a1eda08cb4546cf2 100644 (file)
@@ -273,9 +273,7 @@ evax_shorten_name (char *id)
     }
 
   /* We only need worry about krunching the base symbol.  */
-  base_id = xmalloc (suffix_dotdot - prefix_dotdot + 1);
-  strncpy (base_id, &id[prefix_dotdot], suffix_dotdot - prefix_dotdot);
-  base_id [suffix_dotdot - prefix_dotdot] = 0;
+  base_id = xmemdup0 (&id[prefix_dotdot], suffix_dotdot - prefix_dotdot);
 
   if (strlen (base_id) > MAX_LABEL_LENGTH)
     {
@@ -299,8 +297,7 @@ evax_shorten_name (char *id)
        strcat (new_id, suffix);
 
       /* Save it on the heap and return.  */
-      return_id = xmalloc (strlen (new_id) + 1);
-      strcpy (return_id, new_id);
+      return_id = xstrdup (new_id);
 
       return return_id;
     }
index f823b5ce431ccc3bd4dac5c7961c8b47ec47be51..ba079f36028f96375600cd35c2bde24982971475 100644 (file)
@@ -206,16 +206,7 @@ obj_mach_o_make_or_get_sect (char * segname, char * sectname,
       /* There is no normal BFD section name for this section.  Create one.
          The name created doesn't really matter as it will never be written
          on disk.  */
-      size_t seglen = strlen (segname);
-      size_t sectlen = strlen (sectname);
-      char *n;
-
-      n = xmalloc (seglen + 1 + sectlen + 1);
-      memcpy (n, segname, seglen);
-      n[seglen] = '.';
-      memcpy (n + seglen + 1, sectname, sectlen);
-      n[seglen + 1 + sectlen] = 0;
-      name = n;
+      name = concat (segname, ".", sectname, (char *) NULL);
       if (specified_mask & SECT_TYPE_SPECIFIED)
        sectype = usectype;
       else
index 9f8764e5c5306ff367638a2248100cfcbe3784d2..8213a18d9d44f1988fe2f0a0edeb7eaccbed4c87 100644 (file)
@@ -1241,9 +1241,7 @@ create_register_alias (char *newname, char *p)
   nlen = strlen (newname);
 #endif
 
-  nbuf = xmalloc (nlen + 1);
-  memcpy (nbuf, newname, nlen);
-  nbuf[nlen] = '\0';
+  nbuf = xmemdup0 (newname, nlen);
 
   /* Create aliases under the new name as stated; an all-lowercase
      version of the new name; and an all-uppercase version of the new
index 89eaf88603da7a3ce3fab869b201384c80e1ea9d..638f16006aa1e6d7798ccab7ff6387832264a9bb 100644 (file)
@@ -1417,9 +1417,7 @@ load_expression (int targreg,
                    ptr1 = strstr (symname, "..") + 2;
                    if (ptr1 > ptr2)
                      ptr1 = symname;
-                   psymname = (char *) xmalloc (ptr2 - ptr1 + 1);
-                   memcpy (psymname, ptr1, ptr2 - ptr1);
-                   psymname [ptr2 - ptr1] = 0;
+                   psymname = xmemdup0 (ptr1, ptr2 - ptr1);
 
                    gas_assert (insn.nfixups + 1 <= MAX_INSN_FIXUPS);
                    insn.fixups[insn.nfixups].reloc = BFD_RELOC_ALPHA_LDA;
@@ -3959,9 +3957,7 @@ s_alpha_file (int ignore ATTRIBUTE_UNUSED)
       discard_rest_of_line ();
 
       len = input_line_pointer - start;
-      first_file_directive = (char *) xmalloc (len + 1);
-      memcpy (first_file_directive, start, len);
-      first_file_directive[len] = '\0';
+      first_file_directive = xmemdup0 (start, len);
 
       input_line_pointer = start;
     }
@@ -4214,9 +4210,7 @@ s_alpha_section_name (void)
          return NULL;
        }
 
-      name = xmalloc (end - input_line_pointer + 1);
-      memcpy (name, input_line_pointer, end - input_line_pointer);
-      name[end - input_line_pointer] = '\0';
+      name = xmemdup0 (input_line_pointer, end - input_line_pointer);
       input_line_pointer = end;
     }
   SKIP_WHITESPACE ();
@@ -6283,10 +6277,7 @@ tc_gen_reloc (asection *sec ATTRIBUTE_UNUSED,
       if (pname_len > 4 && strcmp (pname + pname_len - 4, "..en") == 0)
        {
          symbolS *sym;
-         char *my_pname = (char *) xmalloc (pname_len - 4 + 1);
-
-         memcpy (my_pname, pname, pname_len - 4);
-         my_pname [pname_len - 4] = 0;
+         char *my_pname = xmemdup0 (pname, pname_len - 4);
          sym = symbol_find (my_pname);
          free (my_pname);
          if (sym == NULL)
index b64174fb1c10fcf278056f9d27e20cd5e2ea1451..67c0ec2d8a3f5c77e4cff1b3a0432120b0b64f60 100644 (file)
@@ -2262,9 +2262,7 @@ md_assemble (char *str)
 
   /* Split off the opcode.  */
   opnamelen = strspn (str, "abcdefghijklmnopqrstuvwxyz_0123468");
-  opname = xmalloc (opnamelen + 1);
-  memcpy (opname, str, opnamelen);
-  opname[opnamelen] = '\0';
+  opname = xmemdup0 (str, opnamelen);
 
   /* Signalize we are assmbling the instructions.  */
   assembling_insn = TRUE;
index 3c7e0141a5d95f3e4b27387bc66f3615183d646a..50a658b8c158bfad6965af857ff1f430d1ee1a74 100644 (file)
@@ -2267,9 +2267,7 @@ create_register_alias (char * newname, char *p)
   nlen = strlen (newname);
 #endif
 
-  nbuf = xmalloc (nlen + 1);
-  memcpy (nbuf, newname, nlen);
-  nbuf[nlen] = '\0';
+  nbuf = xmemdup0 (newname, nlen);
 
   /* Create aliases under the new name as stated; an all-lowercase
      version of the new name; and an all-uppercase version of the new
@@ -2432,9 +2430,7 @@ create_neon_reg_alias (char *newname, char *p)
   namelen = strlen (newname);
 #endif
 
-  namebuf = xmalloc (namelen + 1);
-  strncpy (namebuf, newname, namelen);
-  namebuf[namelen] = '\0';
+  namebuf = xmemdup0 (newname, namelen);
 
   insert_neon_reg_alias (namebuf, basereg->number, basetype,
                         typeinfo.defined != 0 ? &typeinfo : NULL);
@@ -21901,10 +21897,7 @@ start_unwind_section (const segT text_seg, int idx)
   const char * prefix;
   const char * prefix_once;
   const char * group_name;
-  size_t prefix_len;
-  size_t text_len;
   char * sec_name;
-  size_t sec_name_len;
   int type;
   int flags;
   int linkonce;
@@ -21933,13 +21926,7 @@ start_unwind_section (const segT text_seg, int idx)
       text_name += strlen (".gnu.linkonce.t.");
     }
 
-  prefix_len = strlen (prefix);
-  text_len = strlen (text_name);
-  sec_name_len = prefix_len + text_len;
-  sec_name = (char *) xmalloc (sec_name_len + 1);
-  memcpy (sec_name, prefix, prefix_len);
-  memcpy (sec_name + prefix_len, text_name, text_len);
-  sec_name[prefix_len + text_len] = '\0';
+  sec_name = concat (prefix, text_name, (char *) NULL);
 
   flags = SHF_ALLOC;
   linkonce = 0;
index 6bf1bba5c4572cf928dbe52d8ffd89ebc1dec0bc..aea78dc953688035809ffd224b564e0bf5cacb0b 100644 (file)
@@ -5974,11 +5974,8 @@ pa_build_unwind_subspace (struct call_info *call_info)
   /* Replace the start symbol with a local symbol that will be reduced
      to a section offset.  This avoids problems with weak functions with
      multiple definitions, etc.  */
-  name = xmalloc (strlen ("L$\001start_")
-                 + strlen (S_GET_NAME (call_info->start_symbol))
-                 + 1);
-  strcpy (name, "L$\001start_");
-  strcat (name, S_GET_NAME (call_info->start_symbol));
+  name = concat ("L$\001start_", S_GET_NAME (call_info->start_symbol),
+                (char *) NULL);
 
   /* If we have a .procend preceded by a .exit, then the symbol will have
      already been defined.  In that case, we don't want another unwind
@@ -6414,6 +6411,7 @@ hppa_elf_mark_end_of_function (void)
   /* ELF does not have EXIT relocations.  All we do is create a
      temporary symbol marking the end of the function.  */
   char *name;
+  symbolS *symbolP;
 
   if (last_call_info == NULL || last_call_info->start_symbol == NULL)
     {
@@ -6422,48 +6420,37 @@ hppa_elf_mark_end_of_function (void)
       return;
     }
 
-  name = xmalloc (strlen ("L$\001end_")
-                 + strlen (S_GET_NAME (last_call_info->start_symbol))
-                 + 1);
-  if (name)
-    {
-      symbolS *symbolP;
-
-      strcpy (name, "L$\001end_");
-      strcat (name, S_GET_NAME (last_call_info->start_symbol));
-
-      /* If we have a .exit followed by a .procend, then the
-        symbol will have already been defined.  */
-      symbolP = symbol_find (name);
-      if (symbolP)
-       {
-         /* The symbol has already been defined!  This can
-            happen if we have a .exit followed by a .procend.
-
-            This is *not* an error.  All we want to do is free
-            the memory we just allocated for the name and continue.  */
-         xfree (name);
-       }
-      else
-       {
-         /* symbol value should be the offset of the
-            last instruction of the function */
-         symbolP = symbol_new (name, now_seg, (valueT) (frag_now_fix () - 4),
-                               frag_now);
+  name = concat ("L$\001end_", S_GET_NAME (last_call_info->start_symbol),
+                (char *) NULL);
 
-         gas_assert (symbolP);
-         S_CLEAR_EXTERNAL (symbolP);
-         symbol_table_insert (symbolP);
-       }
+  /* If we have a .exit followed by a .procend, then the
+     symbol will have already been defined.  */
+  symbolP = symbol_find (name);
+  if (symbolP)
+    {
+      /* The symbol has already been defined!  This can
+        happen if we have a .exit followed by a .procend.
 
-      if (symbolP)
-       last_call_info->end_symbol = symbolP;
-      else
-       as_bad (_("Symbol '%s' could not be created."), name);
+        This is *not* an error.  All we want to do is free
+        the memory we just allocated for the name and continue.  */
+      xfree (name);
+    }
+  else
+    {
+      /* symbol value should be the offset of the
+        last instruction of the function */
+      symbolP = symbol_new (name, now_seg, (valueT) (frag_now_fix () - 4),
+                           frag_now);
 
+      gas_assert (symbolP);
+      S_CLEAR_EXTERNAL (symbolP);
+      symbol_table_insert (symbolP);
     }
+
+  if (symbolP)
+    last_call_info->end_symbol = symbolP;
   else
-    as_bad (_("No memory for symbol name."));
+    as_bad (_("Symbol '%s' could not be created."), name);
 }
 #endif
 
index a9d3a595a2636940b818f844af059077eb87899c..a62e3cbf784857ad09ea902b7753077144a870c8 100644 (file)
@@ -3159,10 +3159,7 @@ nios2_modify_arg (char **parsed_args, const char *modifier,
 {
   char *tmp = parsed_args[ndx];
 
-  parsed_args[ndx]
-    = (char *) malloc (strlen (parsed_args[ndx]) + strlen (modifier) + 1);
-  strcpy (parsed_args[ndx], tmp);
-  strcat (parsed_args[ndx], modifier);
+  parsed_args[ndx] = concat (tmp, modifier, (char *) NULL);
 }
 
 /* Modify parsed_args[ndx] by negating that argument.  */
@@ -3172,13 +3169,7 @@ nios2_negate_arg (char **parsed_args, const char *modifier ATTRIBUTE_UNUSED,
 {
   char *tmp = parsed_args[ndx];
 
-  parsed_args[ndx]
-    = (char *) malloc (strlen ("~(") + strlen (parsed_args[ndx]) +
-                      strlen (")+1") + 1);
-
-  strcpy (parsed_args[ndx], "~(");
-  strcat (parsed_args[ndx], tmp);
-  strcat (parsed_args[ndx], ")+1");
+  parsed_args[ndx] = concat ("~(", tmp, ")+1", (char *) NULL);
 }
 
 /* The function nios2_swap_args swaps the pointers at indices index_1 and
index e0af5b5162131b67d41a49737d32f27c1881e524..2c7af2077cf30a457c1cfb0216219586d396fb18 100644 (file)
@@ -531,10 +531,7 @@ rx_section (int ignore)
 
       if (*p != '"' && *p != '#')
        {
-         char * name = (char *) xmalloc (len + 1);
-
-         strncpy (name, input_line_pointer, len);
-         name[len] = 0;
+         char *name = xmemdup0 (input_line_pointer, len);
 
          input_line_pointer = p;
          parse_rx_section (name);
index eb1c287478f3249d8d1ea5f734106fd98bdecb66..ec08173b94cfd5bacc1971cff6b0ac504f59897c 100644 (file)
@@ -3273,8 +3273,7 @@ sh64_consume_datalabel (const char *name, expressionS *exp,
            {
              symbolS *dl_symp;
              const char * sname = S_GET_NAME (symp);
-             char *dl_name
-               = xmalloc (strlen (sname) + sizeof (DATALABEL_SUFFIX));
+             char *dl_name = concat (sname, DATALABEL_SUFFIX, (char *) NULL);
 
              /* Now we copy the datalabel-qualified symbol into a symbol
                 with the same name, but with " DL" appended.  We mark the
@@ -3282,8 +3281,6 @@ sh64_consume_datalabel (const char *name, expressionS *exp,
                 the main symbol, so we don't have to inspect all symbol
                 names.  Note that use of "datalabel" is not expected to
                 be a common case.  */
-             strcpy (dl_name, sname);
-             strcat (dl_name, DATALABEL_SUFFIX);
 
              /* A FAKE_LABEL_NAME marks "$" or ".".  There can be any
                 number of them and all have the same (faked) name; we
index 725691c3acaaa40922bae2bd64015896ec2a2ebc..f6c332fc680da354dd6b1425e8876cbaa825c50c 100644 (file)
@@ -380,11 +380,10 @@ tic30_find_parallel_insn (char *current_line, char *next_line)
        }
       }
   }
-  parallel_insn = malloc (strlen (first_opcode) + strlen (first_operands)
-                         + strlen (second_opcode) + strlen (second_operands) + 8);
-  sprintf (parallel_insn, "q_%s_%s %s | %s",
-          first_opcode, second_opcode,
-          first_operands, second_operands);
+
+  parallel_insn = concat ("q_", first_opcode, "_", second_opcode, " ",
+                         first_operands, " | ", second_operands,
+                         (char *) NULL);
   debug ("parallel insn = %s\n", parallel_insn);
   return parallel_insn;
 }
index 5dd772e015ad06be7b8d2b29f5565cdd6f2e46e1..ddda0c1b1a48cda06719b8a88d1dd27d53ea92df 100644 (file)
@@ -1932,8 +1932,7 @@ tic54x_include (int ignored ATTRIBUTE_UNUSED)
      and a .newblock.
      The included file will be inserted before the newblock, so that the
      newblock is executed after the included file is processed.  */
-  input = xmalloc (sizeof (newblock) + strlen (filename) + 4);
-  sprintf (input, "\"%s\"\n%s", filename, newblock);
+  input = concat ("\"", filename, "\"\n", newblock, (char *) NULL);
   input_scrub_insert_line (input);
 
   tic54x_clear_local_labels (0);
@@ -2518,10 +2517,8 @@ tic54x_macro_info (const macro_entry *macro)
   /* Put the formal args into the substitution symbol table.  */
   for (entry = macro->formals; entry; entry = entry->next)
     {
-      char *name = strncpy (xmalloc (entry->name.len + 1),
-                           entry->name.ptr, entry->name.len);
-      char *value = strncpy (xmalloc (entry->actual.len + 1),
-                            entry->actual.ptr, entry->actual.len);
+      char *name = xstrndup (entry->name.ptr, entry->name.len);
+      char *value = xstrndup (entry->actual.ptr, entry->actual.len);
 
       name[entry->name.len] = '\0';
       value[entry->actual.len] = '\0';
@@ -4293,9 +4290,7 @@ subsym_get_arg (char *line, const char *terminators, char **str, int nosub)
       while (ISDIGIT (*ptr))
        ++ptr;
       endp = ptr;
-      *str = xmalloc (ptr - line + 1);
-      strncpy (*str, line, ptr - line);
-      (*str)[ptr - line] = 0;
+      *str = xmemdup0 (line, ptr - line);
     }
   else if (is_string)
     {
@@ -4327,9 +4322,7 @@ subsym_get_arg (char *line, const char *terminators, char **str, int nosub)
            ++term;
        }
       endp = ptr;
-      *str = xmalloc (ptr - line + 1);
-      strncpy (*str, line, ptr - line);
-      (*str)[ptr - line] = 0;
+      *str = xmemdup0 (line, ptr - line);
       /* Do simple substitution, if available.  */
       if (!nosub && (value = subsym_lookup (*str, macro_level)) != NULL)
        *str = value;
@@ -4452,8 +4445,7 @@ subsym_substitute (char *line, int forced)
              continue;
            }
          *ptr++ = '\0';
-         tmp = xmalloc (strlen (head) + 2 + strlen (ptr) + 1);
-         sprintf (tmp, "%s==%s", head, ptr);
+         tmp = concat (head, "==", ptr, (char *) NULL);
          /* Continue examining after the '=='.  */
          ptr = tmp + strlen (head) + 2;
          free (replacement);
@@ -4751,9 +4743,7 @@ tic54x_start_line_hook (void)
   endp = input_line_pointer;
   while (!is_end_of_line[(int) *endp++])
     ;
-  line = xmalloc (endp - input_line_pointer + 1);
-  strncpy (line, input_line_pointer, endp - input_line_pointer + 1);
-  line[endp - input_line_pointer] = 0;
+  line = xmemdup0 (input_line_pointer, endp - input_line_pointer);
 
   /* Scan ahead for parallel insns.  */
   parallel_on_next_line_hint = next_line_shows_parallel (endp);
index b7d15823b12fcd3a569a959c78dd00121262f900..4aa421b6156328dd8420555f106073851810c6a5 100644 (file)
@@ -1594,10 +1594,7 @@ xtensa_literal_prefix (void)
                "abcdefghijklmnopqrstuvwxyz_/0123456789.$");
 
   /* Get a null-terminated copy of the name.  */
-  name = xmalloc (len + 1);
-  gas_assert (name);
-  strncpy (name, input_line_pointer, len);
-  name[len] = 0;
+  name = xmemdup0 (input_line_pointer, len);
 
   /* Skip the name in the input line.  */
   input_line_pointer += len;
@@ -2239,8 +2236,7 @@ xg_reverse_shift_count (char **cnt_argp)
   cnt_arg = *cnt_argp;
 
   /* replace the argument with "31-(argument)" */
-  new_arg = (char *) xmalloc (strlen (cnt_arg) + 6);
-  sprintf (new_arg, "31-(%s)", cnt_arg);
+  new_arg = concat ("31-(", cnt_argp, ")", (char *) NULL);
 
   free (cnt_arg);
   *cnt_argp = new_arg;
index 3adbf2aa60a68fc308ade94f2836f0b7416b8c01..9b4994ac8a2e83f31295f7ec3e37d3ad1a1b9f91 100644 (file)
@@ -820,9 +820,7 @@ enter_opname_n (const char *name, int len)
        return op->opname;
     }
   op = (opname_e *) xmalloc (sizeof (opname_e));
-  op->opname = (char *) xmalloc (len + 1);
-  strncpy (op->opname, name, len);
-  op->opname[len] = '\0';
+  op->opname = xmemdup0 (name, len);
   return op->opname;
 }
 
@@ -1127,9 +1125,7 @@ split_string (split_rec *rec,
       else
        {
          len = p - q;
-         rec->vec[i] = (char *) xmalloc (sizeof (char) * (len + 1));
-         strncpy (rec->vec[i], q, len);
-         rec->vec[i][len] = '\0';
+         rec->vec[i] = xmemdup0 (q, len);
          p++;
        }
 
index 27b264634bcee2353eb347855c275db562c98da0..f0c46e2d530d3e5df7a028b2d66a6d32ec9935ca 100644 (file)
@@ -515,9 +515,7 @@ get_filenum (const char *filename, unsigned int num)
              dirs = XRESIZEVEC (char *, dirs, dirs_allocated);
            }
 
-         dirs[dir] = (char *) xmalloc (dir_len + 1);
-         memcpy (dirs[dir], filename, dir_len);
-         dirs[dir][dir_len] = '\0';
+         dirs[dir] = xmemdup0 (filename, dir_len);
          dirs_in_use = dir + 1;
        }
     }
@@ -1297,11 +1295,7 @@ process_entries (segT seg, struct line_entry *e)
       sec_name = bfd_get_section_name (stdoutput, seg);
       if (strcmp (sec_name, ".text") != 0)
        {
-         unsigned int len;
-
-         len = strlen (sec_name);
-         name = xmalloc (len + 11 + 2);
-         sprintf (name, ".debug_line%s", sec_name);
+         name = concat (".debug_line", sec_name, (char *) NULL);
          subseg_set (subseg_get (name, FALSE), 0);
        }
       else
index afe46c4764424077e6d471cdc12aaa6c40a9ca72..b1cdb38bab58add5550d1affbbbfcd363b298279 100644 (file)
@@ -1155,11 +1155,8 @@ operand (expressionS *expressionP, enum expr_mode mode)
              SKIP_WHITESPACE ();
              c = get_symbol_name (& name);
 
-             buf = (char *) xmalloc (strlen (name) + 10);
-             if (start)
-               sprintf (buf, ".startof.%s", name);
-             else
-               sprintf (buf, ".sizeof.%s", name);
+             buf = concat (start ? ".startof." : ".sizeof.", name,
+                           (char *) NULL);
              symbolP = symbol_make (buf);
              free (buf);
 
@@ -1301,11 +1298,8 @@ operand (expressionS *expressionP, enum expr_mode mode)
 
              c = get_symbol_name (& name);
 
-             buf = (char *) xmalloc (strlen (name) + 10);
-             if (start)
-               sprintf (buf, ".startof.%s", name);
-             else
-               sprintf (buf, ".sizeof.%s", name);
+             buf = concat (start ? ".startof." : ".sizeof.", name,
+                           (char *) NULL);
              symbolP = symbol_make (buf);
              free (buf);
 
index 2c09f715e56d6e5f4ee771bfa56c75a4a142a911..1a4e2bb0b941ba22f537e77d3ad823b8d2f4d7af 100644 (file)
@@ -857,9 +857,7 @@ alloc_entry (e_processor processor, e_type type,
   if (e)
     {
       memset (e, 0, sizeof (struct itbl_entry));
-      e->name = (char *) malloc (sizeof (strlen (name)) + 1);
-      if (e->name)
-       strcpy (e->name, name);
+      e->name = xstrdup (name);
       e->processor = processor;
       e->type = type;
       e->value = value;
index c90c575a5aff3aec6c8d136b43897ba25367c23c..e5fb3a0a9dd4c5405cdf439642b728da1e4ce2fa 100644 (file)
@@ -234,11 +234,8 @@ listing_message (const char *name, const char *message)
 {
   if (listing_tail != (list_info_type *) NULL)
     {
-      unsigned int l = strlen (name) + strlen (message) + 1;
-      char *n = (char *) xmalloc (l);
+      char *n = concat (name, message, (char *) NULL);
       struct list_message *lm = XNEW (struct list_message);
-      strcpy (n, name);
-      strcat (n, message);
       lm->message = n;
       lm->next = NULL;
 
@@ -1555,9 +1552,7 @@ listing_title (int depth)
          if (listing)
            {
              length = input_line_pointer - start;
-             ttl = (char *) xmalloc (length + 1);
-             memcpy (ttl, start, length);
-             ttl[length] = 0;
+             ttl = xmemdup0 (start, length);
              listing_tail->edict = depth ? EDICT_SBTTL : EDICT_TITLE;
              listing_tail->edict_arg = ttl;
            }
index 615bfdae4fdd137a210ed7a8325cffa29f7b16ca..6bfce3180cff7976aae35d586ca18231b9740edc 100644 (file)
@@ -1250,9 +1250,7 @@ check_macro (const char *line, sb *expand,
   if (is_name_ender (*s))
     ++s;
 
-  copy = (char *) xmalloc (s - line + 1);
-  memcpy (copy, line, s - line);
-  copy[s - line] = '\0';
+  copy = xmemdup0 (line, s - line);
   for (cls = copy; *cls != '\0'; cls ++)
     *cls = TOLOWER (*cls);
 
index 08b84393150b27bdaeeb1be04719740d00c4f6fd..10e271fcf151b3d35a1e0b8413a03a098ac6194a 100644 (file)
@@ -429,9 +429,7 @@ s_xstab (int what)
      the stab section name.  */
   if (saved_secname == 0 || strcmp (saved_secname, stab_secname))
     {
-      stabstr_secname = (char *) xmalloc (strlen (stab_secname) + 4);
-      strcpy (stabstr_secname, stab_secname);
-      strcat (stabstr_secname, "str");
+      stabstr_secname = concat (stab_secname, "str", (char *) NULL);
       if (saved_secname)
        {
          free (saved_secname);
index 4c3137a12786f0da059195e6c81bcbf2f2952e05..0d5a85440938d897cefdddee505d4cce80594a77 100644 (file)
@@ -3220,25 +3220,16 @@ symbol_relc_make_expr (expressionS * exp)
 
   if (opstr == NULL)
     concat_string = NULL;
+  else if (arity == 0)
+    concat_string = xstrdup (opstr);
+  else if (arity == 1)
+    concat_string = concat (opstr, ":", operands[0], (char *) NULL);
+  else if (arity == 2)
+    concat_string = concat (opstr, ":", operands[0], ":", operands[1],
+                           (char *) NULL);
   else
-    {
-      /* Allocate new string; include inter-operand padding gaps etc.  */
-      concat_string = xmalloc (strlen (opstr)
-                              + 1
-                              + (arity >= 1 ? (strlen (operands[0]) + 1 ) : 0)
-                              + (arity >= 2 ? (strlen (operands[1]) + 1 ) : 0)
-                              + (arity >= 3 ? (strlen (operands[2]) + 0 ) : 0)
-                              + 1);
-      gas_assert (concat_string != NULL);
-
-      /* Format the thing.  */
-      sprintf (concat_string,
-              (arity == 0 ? "%s" :
-               arity == 1 ? "%s:%s" :
-               arity == 2 ? "%s:%s:%s" :
-               /* arity == 3 */ "%s:%s:%s:%s"),
-              opstr, operands[0], operands[1], operands[2]);
-    }
+    concat_string = concat (opstr, ":", operands[0], ":", operands[1], ":",
+                           operands[2], (char *) NULL);
 
   /* Free operand strings (not opstr).  */
   if (arity >= 1) xfree (operands[0]);
index 15330cfc3345a5b14cbb1d87def476f52c4e946b..c965e6878562815dc2eddf0b2a789301b5898e94 100644 (file)
@@ -1545,10 +1545,7 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
   gas_assert (x);
   if (!compression_header_size)
     {
-      compressed_name = (char *) xmalloc (strlen (section_name) + 2);
-      compressed_name[0] = '.';
-      compressed_name[1] = 'z';
-      strcpy (compressed_name + 2, section_name + 1);
+      compressed_name = concat (".z", section_name + 1, (char *) NULL);
       bfd_section_name (stdoutput, sec) = compressed_name;
     }
 }
This page took 0.06074 seconds and 4 git commands to generate.