This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch to use concat instead of xmalloc/sprintf


This patch converts all the uses of xmalloc/sprintf that I could find
into calls to concat.  Bootstrapped on solaris2.7, no regressions.

Ok to install?

		--Kaveh



2001-04-19  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* collect2.c (main): Use concat in lieu of xmalloc/sprintf.
	(write_c_file_stat): Likewise.

	* dbxout.c (dbxout_init): Likewise.

	* profile.c (output_func_start_profiler): Likewise.

cp:
	* xref.c (GNU_xref_file): Use concat in lieu of xmalloc/sprintf.

f:
	* com.c (ffecom_subscript_check_): Use concat in lieu of
	xmalloc/sprintf.

diff -rup orig/egcs-CVS20010418/gcc/collect2.c egcs-CVS20010418/gcc/collect2.c
--- orig/egcs-CVS20010418/gcc/collect2.c	Wed Mar 21 19:53:48 2001
+++ egcs-CVS20010418/gcc/collect2.c	Thu Apr 19 14:30:16 2001
@@ -1269,9 +1269,8 @@ main (argc, argv)
 
   if (exports.first)
     {
-      char *buf = xmalloc (strlen (export_file) + 5);
-
-      sprintf (buf, "-bE:%s", export_file);
+      char *buf = concat ("-bE:", export_file, NULL);
+      
       *ld1++ = buf;
       *ld2++ = buf;
 
@@ -1435,13 +1434,7 @@ main (argc, argv)
   /* Tell the linker that we have initializer and finalizer functions.  */
 #ifdef LD_INIT_SWITCH
 #ifdef COLLECT_EXPORT_LIST
-  {
-    /* option name + functions + colons + NULL */
-    char *buf = xmalloc (strlen (LD_INIT_SWITCH)
-			 + strlen(initname) + strlen(fininame) + 3);
-    sprintf (buf, "%s:%s:%s", LD_INIT_SWITCH, initname, fininame);
-    *ld2++ = buf;
-  }
+  *ld2++ = concat (LD_INIT_SWITCH, ":", initname, ":", fininame, NULL);
 #else
   *ld2++ = LD_INIT_SWITCH;
   *ld2++ = initname;
@@ -1456,12 +1449,7 @@ main (argc, argv)
       /* If we did not add export flag to link arguments before, add it to
 	 second link phase now.  No new exports should have been added.  */
       if (! exports.first)
-	{
-	  char *buf = xmalloc (strlen (export_file) + 5);
-
-	  sprintf (buf, "-bE:%s", export_file);
-	  *ld2++ = buf;
-	}
+	*ld2++ = concat ("-bE:", export_file, NULL);
 
       add_to_list (&exports, initname);
       add_to_list (&exports, fininame);
@@ -1878,13 +1866,8 @@ write_c_file_stat (stream, name)
     notice ("\nwrite_c_file - output name is %s, prefix is %s\n",
 	    output_file, prefix);
 
-#define INIT_NAME_FORMAT "_GLOBAL__FI_%s"
-  initname = xmalloc (strlen (prefix) + sizeof (INIT_NAME_FORMAT) - 2);
-  sprintf (initname, INIT_NAME_FORMAT, prefix);
-
-#define FINI_NAME_FORMAT "_GLOBAL__FD_%s"
-  fininame = xmalloc (strlen (prefix) + sizeof (FINI_NAME_FORMAT) - 2);
-  sprintf (fininame, FINI_NAME_FORMAT, prefix);
+  initname = concat ("_GLOBAL__FI_", prefix, NULL);
+  fininame = concat ("_GLOBAL__FD_", prefix, NULL);
 
   free (prefix);
 
diff -rup orig/egcs-CVS20010418/gcc/dbxout.c egcs-CVS20010418/gcc/dbxout.c
--- orig/egcs-CVS20010418/gcc/dbxout.c	Wed Apr 18 02:15:38 2001
+++ egcs-CVS20010418/gcc/dbxout.c	Thu Apr 19 14:33:41 2001
@@ -395,11 +395,7 @@ dbxout_init (asm_file, input_file_name, 
 #endif
     {
       if (!cwd && (cwd = getpwd ()) && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
-	{
-	  char *wdslash = xmalloc (strlen (cwd) + sizeof (FILE_NAME_JOINER));
-	  sprintf (wdslash, "%s%s", cwd, FILE_NAME_JOINER);
-	  cwd = wdslash;
-	}
+	cwd = concat (cwd, FILE_NAME_JOINER, NULL);
       if (cwd)
 	{
 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
diff -rup orig/egcs-CVS20010418/gcc/profile.c egcs-CVS20010418/gcc/profile.c
--- orig/egcs-CVS20010418/gcc/profile.c	Thu Mar 22 13:48:30 2001
+++ egcs-CVS20010418/gcc/profile.c	Thu Apr 19 14:40:48 2001
@@ -1090,8 +1090,7 @@ output_func_start_profiler ()
 
   fnname = get_file_function_name ('I');
   cfnname = IDENTIFIER_POINTER (fnname);
-  name = xmalloc (strlen (cfnname) + 5);
-  sprintf (name, "%sGCOV",cfnname);
+  name = concat (cfnname, "GCOV", NULL);
   fnname = get_identifier (name);
   free (name);
 
diff -rup orig/egcs-CVS20010418/gcc/cp/xref.c egcs-CVS20010418/gcc/cp/xref.c
--- orig/egcs-CVS20010418/gcc/cp/xref.c	Thu Nov  2 14:03:58 2000
+++ egcs-CVS20010418/gcc/cp/xref.c	Thu Apr 19 14:49:34 2001
@@ -205,14 +205,7 @@ GNU_xref_file (name)
   if (FILE_NAME_ABSOLUTE_P (name) || ! wd_name)
     xf->outname = xf->name;
   else
-    {
-      char *nmbuf
-	= (char *) xmalloc (strlen (wd_name) + strlen (FILE_NAME_JOINER)
-			    + strlen (name) + 1);
-      sprintf (nmbuf, "%s%s%s", wd_name, FILE_NAME_JOINER, name);
-      name = nmbuf;
-      xf->outname = nmbuf;
-    }
+    xf->outname = name = concat (wd_name, FILE_NAME_JOINER, name, NULL);
 
   fprintf (xref_file, "FIL %s %s 0\n", name, wd_name);
 
diff -rup orig/egcs-CVS20010418/gcc/f/com.c egcs-CVS20010418/gcc/f/com.c
--- orig/egcs-CVS20010418/gcc/f/com.c	Thu Apr 12 18:18:51 2001
+++ egcs-CVS20010418/gcc/f/com.c	Thu Apr 19 14:55:55 2001
@@ -694,10 +694,8 @@ ffecom_subscript_check_ (tree array, tre
     switch (total_dims)
       {
       case 0:
-	var = xmalloc (strlen (array_name) + 20);
-	sprintf (var, "%s[%s-substring]",
-		 array_name,
-		 dim ? "end" : "start");
+	var = concat (array_name, "[", (dim ? "end" : "start"),
+		      "-substring]", NULL);
 	len = strlen (var) + 1;
 	arg1 = build_string (len, var);
 	free (var);
@@ -740,13 +738,10 @@ ffecom_subscript_check_ (tree array, tre
 			      convert (TREE_TYPE (element),
 				       integer_one_node)));
 
-    proc = xmalloc ((len = strlen (input_filename)
-		     + IDENTIFIER_LENGTH (DECL_NAME (current_function_decl))
-		     + 2));
-
-    sprintf (&proc[0], "%s/%s",
-	     input_filename,
-	     IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
+    proc = concat (input_filename, "/",
+		   IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
+		   NULL);
+    len = strlen (proc) + 1;
     arg3 = build_string (len, proc);
 
     free (proc);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]