[PATCH] vcut - Fix cut failure with discarded output

Michael Gold <[email protected]> Sat, 19 May 2012 12:04:58 -0400
Newsgroups gmane.comp.multimedia.ogg.vorbis.devel
Message-ID <[email protected]>
Hi all,

Here's a patch to fix a spurious failure in vcut.  Please apply.

If the user wants to drop the output (i.e. the filename is given as ".")
and the cutpoint is found before open_output_file is called, drop_output
will not have been set, and vcut will fail with the error "Can't produce
a file starting and ending between sample positions [...]".  But when no
output file is desired, we can safely ignore this condition.

This changes the code to call the new function will_drop_output, instead
of reading s->drop_output.  This function checks the filename as well as
s->drop_output.

-- Michael

_______________________________________________
Vorbis-dev mailing list
[email protected]
http://lists.xiph.org/mailman/listinfo/vorbis-dev
vcut-first-packet.diff (text/x-diff, 1.6 KB)
--- vcut/vcut.c.orig	2012-05-19 11:04:34.336204739 -0400
+++ vcut/vcut.c	2012-05-19 11:47:17.884678896 -0400
@@ -202,13 +202,21 @@
 	return 0;
 }
 
+static int will_drop_output(vcut_state *s)
+{
+	return s->drop_output
+		|| !s->output_filename
+		|| (strcmp(s->output_filename, ".") == 0);
+}
+
 /* Opens the given output file; or sets s->drop_output if the filename is ".".
  * Returns 0 for success, or -1 on failure. */
-static int open_output_file(vcut_state *s, char *filename)
+static int open_output_file(vcut_state *s)
 {
 	assert(s->out == NULL);
 
-	if(strcmp(filename, ".") == 0)
+	s->drop_output = 0;
+	if(will_drop_output(s))
 	{
 		s->out = NULL;
 		s->drop_output = 1;
@@ -216,13 +224,13 @@
 
 	else
 	{
-                if(strcmp(filename, "-") == 0)
-                        s->out = fdopen(1, "wb");
-                else
-                        s->out = fopen(filename, "wb");
-		s->drop_output = 0;
+		if(strcmp(s->output_filename, "-") == 0)
+			s->out = fdopen(1, "wb");
+		else
+			s->out = fopen(s->output_filename, "wb");
 		if(!s->out) {
-			fprintf(stderr, _("Couldn't open %s for writing\n"), filename);
+			fprintf(stderr, _("Couldn't open %s for writing\n"),
+					s->output_filename);
 			return -1;
 		}
 	}
@@ -235,7 +243,7 @@
 {
 	if(!s->out && !s->drop_output)
 	{
-		if(open_output_file(s, s->output_filename)!=0)
+		if(open_output_file(s)!=0)
 			return -1;
 	}
 
@@ -407,7 +415,7 @@
 			return -1;
 		}
 
-		if(rel_sample < bs && !s->drop_output)
+		if(rel_sample < bs && !will_drop_output(s))
 		{
 			fprintf(stderr, _("Can't produce a file starting"
 					" and ending between sample positions " FORMAT_INT64
signature.asc (application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)

iEYEARECAAYFAk+3xKoACgkQ+RZl+46r4TdQIQCfTSmUwpKVEFAJB5XbpoZ2x5jc
i80An0Vlkgtq5o4wWtDvw7T1OQ0wIWJZ
=sNl3
-----END PGP SIGNATURE-----