socsvn commit: r254913 - soc2013/dpl/head/contrib/xz/src/xz

dpl at FreeBSD.org dpl at FreeBSD.org
Thu Jul 18 11:06:40 UTC 2013


Author: dpl
Date: Thu Jul 18 11:06:39 2013
New Revision: 254913
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254913

Log:
  Bug with the first filename from arguments.
  

Modified:
  soc2013/dpl/head/contrib/xz/src/xz/file_io.c
  soc2013/dpl/head/contrib/xz/src/xz/main.c

Modified: soc2013/dpl/head/contrib/xz/src/xz/file_io.c
==============================================================================
--- soc2013/dpl/head/contrib/xz/src/xz/file_io.c	Thu Jul 18 09:20:51 2013	(r254912)
+++ soc2013/dpl/head/contrib/xz/src/xz/file_io.c	Thu Jul 18 11:06:39 2013	(r254913)
@@ -986,11 +986,14 @@
 		if (opt_format != FORMAT_XZ && opt_format != FORMAT_AUTO)
 			message_fatal(_("--list works only on .xz files "
 			"(--format=xz or --format=auto)"));
+
+	for ( i = 0; i<files; i++) 
+		printf("filename[%d]: %s\n", i, filename[i]);
 			
-	for ( i = 0; i < files; i++) {
-		if (filename[i] == NULL) {
-			break;
-		}
+	for ( i = 0; i<files; i++) {
+		if (filename[i] == NULL) 
+			continue;
+
 		// Set and possibly print the filename for the progress message.
 		message_filename(filename[i]);
 
@@ -1008,7 +1011,9 @@
 		}
 
 		pairs[i] = (file_pair*)malloc(sizeof(file_pair *));
-		pairs[i] = io_open_src(filename[i]);
+		if ( (pairs[i] = io_open_src(filename[i])) == NULL) 
+			continue;
+
 		if( opt_mode != MODE_TEST )
 			io_open_dest(pairs[i]);
 #if defined(CAPSICUM)

Modified: soc2013/dpl/head/contrib/xz/src/xz/main.c
==============================================================================
--- soc2013/dpl/head/contrib/xz/src/xz/main.c	Thu Jul 18 09:20:51 2013	(r254912)
+++ soc2013/dpl/head/contrib/xz/src/xz/main.c	Thu Jul 18 11:06:39 2013	(r254913)
@@ -143,6 +143,9 @@
 main(int argc, char **argv)
 {
 	int forkpid, i, nfiles = 0;
+	//Filenames will be here, and get passed to io_open_files().
+	char **files = (char **)malloc(sizeof(char **));
+
 #if defined(_WIN32) && !defined(__CYGWIN__)
 	InitializeCriticalSection(&exit_status_cs);
 #endif
@@ -214,7 +217,7 @@
 
 	// Process the files given on the command line. Note that if no names
 	// were given, args_parse() gave us a fake "-" filename.
-	for (size_t i = 0; i < args.arg_count && !user_abort; ++i) {
+	for ( i = 0; i < (int)args.arg_count && !user_abort; i++, nfiles++) {
 		if (strcmp("-", args.arg_names[i]) == 0) {
 			// Processing from stdin to stdout. Check that we
 			// aren't writing compressed data to a terminal or
@@ -242,10 +245,19 @@
 			// This way error messages get a proper filename
 			// string and the code still knows that it is
 			// handling the special case of stdin.
-			args.arg_names[i] = (char *)stdin_filename;
+			size_t len = strlen(stdin_filename) + 1;
+			files[i] = malloc(len);
+			strncpy(files[i], stdin_filename, len);
+			files[i][len] = '\0';
+		} else {
+			size_t len = strlen(args.arg_names[i]) +1;
+			files[i] = malloc(len);
+			strncpy(files[i], args.arg_names[i], len);
+			files[i][len] = '\0';
 		}
-		nfiles++;
 	}
+	
+	printf("files[0]: %s\n", files[0]);
 
 	// If --files or --files0 was used, process the filenames from the
 	// given file or stdin. Note that here we don't consider "-" to
@@ -260,19 +272,17 @@
 
 			// read_name() doesn't return empty names.
 			assert(name[0] != '\0');
-			args.arg_names[nfiles] = name;
-			printf("args.args_names[%d]: %s\n", nfiles, args.arg_names[nfiles]);
+			size_t len = strlen(name) + 1;
+			files[nfiles] = malloc(len);
+			files[nfiles] = strncpy(files[nfiles], name, len);
+			files[nfiles][len] = '\0';
 			nfiles++;
-			args.arg_count++;
 		}
 		if (args.files_name != stdin_filename)
 			(void)fclose(args.files_file);
 	}
 
-	for ( i = 0; i < nfiles; i++)
-		printf("file[%d]: %s\n", i, args.arg_names[i]);
-
-	file_pair **pairs = io_open_files(args.arg_names, nfiles);
+	file_pair **pairs = io_open_files(files, nfiles);
 
 	for( i = 0; i < nfiles; i++){
 #if defined(CAPSICUM)
@@ -286,6 +296,7 @@
 			cap_init();
 #endif
 			run(pairs[i]);
+			free(files[i]);
 #if defined(CAPSICUM)
 			exit(0);
 		}


More information about the svn-soc-all mailing list