libiberty.h (reconcat): New function.
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>
Mon, 24 Sep 2001 22:38:22 +0000 (22:38 +0000)
committerKaveh Ghazi <ghazi@gcc.gnu.org>
Mon, 24 Sep 2001 22:38:22 +0000 (22:38 +0000)
include:
* libiberty.h (reconcat): New function.

libiberty:
* concat.c (reconcat): New function.

gcc:
* c-aux-info.c (affix_data_type): Use ATTRIBUTE_MALLOC.  Avoid
leak by passing malloc'ed pointer to reconcat, not concat.

From-SVN: r45789

gcc/ChangeLog
gcc/c-aux-info.c
include/ChangeLog
include/libiberty.h
libiberty/ChangeLog
libiberty/concat.c

index b5c46950ebd32ebff946710dd0049c40c6e4acde..66792a3df58340bca7dd8b486bf953dcf2a06414 100644 (file)
@@ -1,3 +1,8 @@
+2001-09-24  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+       * c-aux-info.c (affix_data_type): Use ATTRIBUTE_MALLOC.  Avoid
+       leak by passing malloc'ed pointer to reconcat, not concat.
+
 2001-09-24  DJ Delorie  <dj@redhat.com>
 
        * varasm.c (array_size_for_constructor): Handle STRING_CSTs also.
index c9daa1d96a1cfcb254ce11e2890c2b59eb9417ac..67ecae6cea174265fc4e0eb0cb9e632b447c7922 100644 (file)
@@ -39,7 +39,7 @@ typedef enum formals_style_enum formals_style;
 
 static const char *data_type;
 
-static char *affix_data_type           PARAMS ((const char *));
+static char *affix_data_type           PARAMS ((const char *)) ATTRIBUTE_MALLOC;
 static const char *gen_formal_list_for_type PARAMS ((tree, formals_style));
 static int   deserves_ellipsis         PARAMS ((tree));
 static const char *gen_formal_list_for_func_def PARAMS ((tree, formals_style));
@@ -96,7 +96,8 @@ affix_data_type (param)
   *p = '\0';
   qualifiers_then_data_type = concat (type_or_decl, data_type, NULL);
   *p = saved;
-  return concat (qualifiers_then_data_type, " ", p, NULL);
+  return reconcat (qualifiers_then_data_type,
+                  qualifiers_then_data_type, " ", p, NULL);
 }
 
 /* Given a tree node which represents some "function type", generate the
index c94394e25105c7ecd61a605d7e64fa73e5d79a88..b44671a39d08117481cb2644afa2ff3acb6cc241 100644 (file)
@@ -1,3 +1,7 @@
+2001-09-24  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+       * libiberty.h (reconcat): New function.
+
 2001-09-18  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * libiberty.h (concat, concat_length, concat_copy, concat_copy2,
index a54e3adf05e096a7f28c5033f9f320cc8354c2e8..315d3106c4b52b19eed34a9773e32ef18241db01 100644 (file)
@@ -91,6 +91,15 @@ extern const char *lbasename PARAMS ((const char *));
 
 extern char *concat PARAMS ((const char *, ...)) ATTRIBUTE_MALLOC;
 
+/* Concatenate an arbitrary number of strings.  You must pass NULL as
+   the last argument of this function, to terminate the list of
+   strings.  Allocates memory using xmalloc.  The first argument is
+   not one of the strings to be concatenated, but if not NULL is a
+   pointer to be freed after the new string is created, similar to the
+   way xrealloc works.  */
+
+extern char *reconcat PARAMS ((char *, const char *, ...)) ATTRIBUTE_MALLOC;
+
 /* Determine the length of concatenating an arbitrary number of
    strings.  You must pass NULL as the last argument of this function,
    to terminate the list of strings.  */
index b68c4c5b81237d87222cc6ca35cc2097d53802fa..1c641169f3094bad67c870ed00f3acf1ae398527 100644 (file)
@@ -1,3 +1,7 @@
+2001-09-24  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+       * concat.c (reconcat): New function.
+
 2001-09-17  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * concat.c (vconcat_length, vconcat_copy, concat_length,
index feed0df819bbce9a73ec303855de7d09ad7208b4..136e8be866ebee04f7cf2e0536708d332b910778 100644 (file)
@@ -171,6 +171,31 @@ concat VPARAMS ((const char *first, ...))
   return newstr;
 }
 
+char *
+reconcat VPARAMS ((char *optr, const char *first, ...))
+{
+  char *newstr;
+
+  /* First compute the size of the result and get sufficient memory.  */
+  VA_OPEN (args, first);
+  VA_FIXEDARG (args, char *, optr);
+  VA_FIXEDARG (args, const char *, first);
+  newstr = (char *) xmalloc (vconcat_length (first, args) + 1);
+  VA_CLOSE (args);
+
+  /* Now copy the individual pieces to the result string. */
+  VA_OPEN (args, first);
+  VA_FIXEDARG (args, char *, optr);
+  VA_FIXEDARG (args, const char *, first);
+  vconcat_copy (newstr, first, args);
+  VA_CLOSE (args);
+
+  if (optr)
+    free (optr);
+
+  return newstr;
+}
+
 #ifdef MAIN
 #define NULLP (char *)0