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]
Other format: [Raw text]

[fastjar patch] Fix for PR java/9532


This fixes a fastjar bug(s).  It's the composite of my two patches noted
in the bug trail.  Tested on i686-pc-linux-gnu (where the second part
of the bug didn't materialize).

OK if the bug submitter confirms this fixes the bugs on Solaris (where 
the bug did fully manifest)?

	PR java/9532
	* jartool.c (main): Give proper error message with -C.
	* jartool.c (add_to_jar): Make getcwd() call portable, and check
	for error return.

Index: jartool.c
===================================================================
RCS file: /cvs/gcc/gcc/fastjar/jartool.c,v
retrieving revision 1.22
diff -u -r1.22 jartool.c
--- jartool.c	31 Jan 2003 22:48:27 -0000	1.22
+++ jartool.c	13 Jun 2003 00:43:05 -0000
@@ -510,7 +510,8 @@
         if(!dir_to_change 
 	   || !file_to_add
 	   || add_to_jar(jarfd, dir_to_change, file_to_add)){
-          printf("Error adding %s to jar archive!\n", arg);
+          printf("Error adding %s (in directory %s) to jar archive!\n", \
+                 file_to_add, dir_to_change);
           exit(1);
         }
       } else {
@@ -817,8 +818,8 @@
   struct dirent *de;
   zipentry *ze;
   int stat_return;
-  char *old_dir = NULL;
-  
+  char old_dir[MAXPATHLEN];
+
   /* This is a quick compatibility fix -- Simon Weijgers <simon@weijgers.com> 
    * It fixes this:
    *   "normal" jar : org/apache/java/io/LogRecord.class
@@ -830,10 +831,12 @@
     file+=2;
   
   /* If new_dir isn't null, we need to change to that directory.  However,
-     we also need to return to the old directory when we're done */
+     we also need to return to the old directory when we're done.  See below.*/
   if(new_dir != NULL){
-    old_dir = getcwd(NULL, 0);
-
+    if (getcwd(old_dir, MAXPATHLEN) == NULL) {
+      perror("getcwd");
+      return 1;
+    }
     if(chdir(new_dir) == -1){
       perror(new_dir);
       return 1;
@@ -957,11 +960,13 @@
     fprintf(stderr, "Illegal file specified: %s\n", file);
   }
   
-  if(old_dir != NULL){
-    if(chdir(old_dir))
+  /* If (and only if!) new_dir != NULL, we switched directories, so
+     we have to switch back to the old directory. */
+  if (new_dir != NULL) {
+    if (chdir(old_dir) == -1) {
       perror(old_dir);
-    
-    free(old_dir);
+      return 1;
+    }
   }
 
   return 0;


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