This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java 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 for JAVA dir


This is patch #2 converting xmalloc/sprintf into concat.  I broke this
java one out since I think the first hunk fixes a memory allocation
bug, thus it might be appropriate for the branch.

The xmalloc length calculates enough space for the two strings, the
"-f" and the "=" (i.e. +3) but not for the trailing NULL.  Using
concat does the right thing.  A safer fix for the branch would be to
bump it to +4, (but IMHO I think the concat is safe too.)

Bootstrapped on solaris2.7, no regressions.  Ok to install?

		--Kaveh


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

	* jvspec.c (lang_specific_driver): Fix memory allocation
	deficit, by using concat in lieu of xmalloc/sprintf.

diff -rup orig/egcs-CVS20010418/gcc/java/jvspec.c egcs-CVS20010418/gcc/java/jvspec.c
--- orig/egcs-CVS20010418/gcc/java/jvspec.c	Fri Mar 23 09:14:06 2001
+++ egcs-CVS20010418/gcc/java/jvspec.c	Thu Apr 19 15:01:40 2001
@@ -436,20 +436,14 @@ lang_specific_driver (in_argc, in_argv, 
       if (strcmp (argv[i], "-classpath") == 0
 	  || strcmp (argv[i], "-CLASSPATH") == 0)
 	{
-	  char* patharg
-	    = (char*) xmalloc (strlen (argv[i]) + strlen (argv[i+1]) + 3);
-	  sprintf (patharg, "-f%s=%s", argv[i]+1, argv[i+1]);
-	  arglist[j] = patharg;
+	  arglist[j] = concat ("-f", argv[i]+1, "=", argv[i+1], NULL);
 	  i++;
 	  continue;
 	}
 
       if (strcmp (argv[i], "-d") == 0)
 	{
-	  char *patharg = (char *) xmalloc (sizeof ("-foutput-class-dir=")
-					    + strlen (argv[i + 1]) + 1);
-	  sprintf (patharg, "-foutput-class-dir=%s", argv[i + 1]);
-	  arglist[j] = patharg;
+	  arglist[j] = concat ("-foutput-class-dir=", argv[i + 1], NULL);
 	  ++i;
 	  continue;
 	}



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