chiark / gitweb /
progs/catsign.c: Don't gratuitously try to open a temporary file.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 13 Aug 2018 20:30:07 +0000 (21:30 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 13 Aug 2018 20:39:05 +0000 (21:39 +0100)
The `merry dance' where we open the necessary output files was bungled,
which caused a temporary file to be opened unless an explicit output
file was requested without buffering.

progs/catsign.c

index accd592f3b8d38a3fe1896d065e6be7dc09b8b22..3cce9c93827ba5d219bff668da2ed783ca1919cb 100644 (file)
@@ -749,14 +749,14 @@ static int verify(int argc, char *argv[])
   } else if (!of || strcmp(of, "-") == 0) {
     v.f |= F_BUFFER;
     ofp = stdout;
-  }
-  if (of && !(v.f & F_BUFFER)) {
+  } else if (of && !(v.f & F_BUFFER)) {
     if ((ofp = fopen(of, (v.f & F_BINARY) ? "wb" : "w")) == 0) {
       die(EXIT_FAILURE, "couldn't open file `%s' for output: %s",
          of, strerror(errno));
     }
     rfp = ofp;
-  } else if ((rfp = tmpfile()) == 0)
+  }
+  if ((v.f & F_BUFFER) && (rfp = tmpfile()) == 0)
     die(EXIT_FAILURE, "couldn't create temporary file: %s", strerror(errno));
 
   /* --- Read the message and verify the signature --- */