make md_parse_option () take a const char *
[binutils-gdb.git] / gas / config / tc-tic54x.c
index e071f95664050e377aa7be33e9ee075f0346cd0c..b8897045973bd32562c5b5158bb33a5de5711e30 100644 (file)
@@ -322,7 +322,6 @@ tic54x_asg (int x ATTRIBUTE_UNUSED)
   int c;
   char *name;
   char *str;
-  char *tmp;
   int quoted = *input_line_pointer == '"';
 
   ILLEGAL_WITHIN_STRUCT ();
@@ -360,12 +359,8 @@ tic54x_asg (int x ATTRIBUTE_UNUSED)
       return;
     }
 
-  tmp = xmalloc (strlen (str) + 1);
-  strcpy (tmp, str);
-  str = tmp;
-  tmp = xmalloc (strlen (name) + 1);
-  strcpy (tmp, name);
-  name = tmp;
+  str = xstrdup (str);
+  name = xstrdup (name);
   subsym_create_or_replace (name, str);
   (void) restore_line_pointer (c);
   demand_empty_rest_of_line ();
@@ -549,21 +544,16 @@ stag_add_field_symbols (struct stag *stag,
                        symbolS *rootsym,
                        const char *root_stag_name)
 {
-  char prefix[strlen (path) + 2];
+  char * prefix;
   struct stag_field *field = stag->field;
 
   /* Construct a symbol for every field contained within this structure
      including fields within structure fields.  */
-  strcpy (prefix, path);
-  if (*path)
-    strcat (prefix, ".");
+  prefix = concat (path, *path ? "." : "", NULL);
 
   while (field != NULL)
     {
-      int len = strlen (prefix) + strlen (field->name) + 2;
-      char *name = xmalloc (len);
-      strcpy (name, prefix);
-      strcat (name, field->name);
+      char *name = concat (prefix, field->name, NULL);
 
       if (rootsym == NULL)
        {
@@ -577,12 +567,10 @@ stag_add_field_symbols (struct stag *stag,
        }
       else
        {
-         char *replacement = xmalloc (strlen (name)
-                                      + strlen (stag->name) + 2);
-         strcpy (replacement, S_GET_NAME (rootsym));
-         strcat (replacement, "+");
-         strcat (replacement, root_stag_name);
-         strcat (replacement, name + strlen (S_GET_NAME (rootsym)));
+         char *replacement;
+
+         replacement = concat (S_GET_NAME (rootsym), "+", root_stag_name,
+                               name + strlen (S_GET_NAME (rootsym)), NULL);
          hash_insert (subsym_hash[0], name, replacement);
        }
 
@@ -593,7 +581,9 @@ stag_add_field_symbols (struct stag *stag,
                                field->offset,
                                rootsym, root_stag_name);
       field = field->next;
+      free (name);
     }
+  free (prefix);
 }
 
 /* Keep track of stag fields so that when structures are nested we can add the
@@ -695,11 +685,12 @@ tic54x_struct (int arg)
     }
   else
     {
-      char label[strlen (S_GET_NAME (line_label)) + 1];
-      strcpy (label, S_GET_NAME (line_label));
-      current_stag->sym = symbol_new (label, absolute_section,
+      char * label = xstrdup (S_GET_NAME (line_label));
+      current_stag->sym = symbol_new (label,
+                                     absolute_section,
                                      (valueT) abs_section_offset,
                                      &zero_address_frag);
+      free (label);
     }
   current_stag->name = S_GET_NAME (current_stag->sym);
   SF_SET_LOCAL (current_stag->sym);
@@ -803,9 +794,9 @@ tic54x_tag (int ignore ATTRIBUTE_UNUSED)
     }
   else
     {
-      char label[strlen (S_GET_NAME (line_label)) + 1];
+      char * label;
 
-      strcpy (label, S_GET_NAME (line_label));
+      label = xstrdup (S_GET_NAME (line_label));
       if (current_stag != NULL)
        stag_add_field (current_stag, label,
                        abs_section_offset - S_GET_VALUE (current_stag->sym),
@@ -818,11 +809,13 @@ tic54x_tag (int ignore ATTRIBUTE_UNUSED)
            {
              as_bad (_(".tag target '%s' undefined"), label);
              ignore_rest_of_line ();
+             free (label);
              return;
            }
          stag_add_field_symbols (stag, S_GET_NAME (sym),
                                  S_GET_VALUE (stag->sym), sym, stag->name);
        }
+      free (label);
     }
 
   /* Bump by the struct size, but only if we're within a .struct section.  */
@@ -933,12 +926,13 @@ tic54x_struct_field (int type)
     }
   else
     {
-      char label[strlen (S_GET_NAME (line_label) + 1)];
+      char * label;
 
-      strcpy (label, S_GET_NAME (line_label));
+      label = xstrdup (S_GET_NAME (line_label));
       stag_add_field (current_stag, label,
                      abs_section_offset - S_GET_VALUE (current_stag->sym),
                      NULL);
+      free (label);
     }
 
   if (current_stag->is_union)
@@ -1871,7 +1865,7 @@ tic54x_clink (int ignored ATTRIBUTE_UNUSED)
 static void
 tic54x_set_default_include (int dot)
 {
-  char *dir = ".";
+  const char *dir = ".";
   char *tmp = NULL;
 
   if (!dot)
@@ -2467,7 +2461,7 @@ const pseudo_typeS md_pseudo_table[] =
 };
 
 int
-md_parse_option (int c, char *arg)
+md_parse_option (int c, const char *arg)
 {
   switch (c)
     {
@@ -2496,7 +2490,7 @@ md_parse_option (int c, char *arg)
       break;
     case OPTION_STDERR_TO_FILE:
       {
-       char *filename = arg;
+       const char *filename = arg;
        FILE *fp = fopen (filename, "w+");
 
        if (fp == NULL)
@@ -2912,7 +2906,7 @@ math_tanh (float arg1, float ignore ATTRIBUTE_UNUSED)
 /* Built-in substitution symbol functions and math functions.  */
 typedef struct
 {
-  char *name;
+  const char *name;
   int (*proc) (char *, char *);
   int nargs;
 } subsym_proc_entry;
@@ -2936,7 +2930,7 @@ static const subsym_proc_entry subsym_procs[] =
 
 typedef struct
 {
-  char *name;
+  const char *name;
   float (*proc) (float, float);
   int nargs;
   int int_return;
@@ -4296,7 +4290,7 @@ tic54x_parse_parallel_insn_lastline (tic54x_insn *insn, char *line)
    replacement on the value.  */
 
 static char *
-subsym_get_arg (char *line, char *terminators, char **str, int nosub)
+subsym_get_arg (char *line, const char *terminators, char **str, int nosub)
 {
   char *ptr = line;
   char *endp;
@@ -4328,7 +4322,7 @@ subsym_get_arg (char *line, char *terminators, char **str, int nosub)
     }
   else
     {
-      char *term = terminators;
+      const char *term = terminators;
       char *value = NULL;
 
       while (*ptr && *ptr != *term)
@@ -4528,7 +4522,7 @@ subsym_substitute (char *line, int forced)
              if (value == NULL)
                {
                  char digit[11];
-                 char *namecopy = strcpy (xmalloc (strlen (name) + 1), name);
+                 char *namecopy = xstrdup (name);
 
                  value = strcpy (xmalloc (strlen (name) + sizeof (digit) + 1),
                                  name);
@@ -4653,7 +4647,7 @@ subsym_substitute (char *line, int forced)
                 substitutions are performed, or a substitution that has been
                 previously made is encountered again.
 
-                put the symbol into the recursion hash table so we only
+                Put the symbol into the recursion hash table so we only
                 try to replace a symbol once.  */
              if (recurse)
                {