Another coverity-spotted buglet:
>From 12ee710119356ccb31ef02d324596b982734db9b Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Tue, 24 May 2011 16:20:59 +0200
Subject: [PATCH] don't call fdopen with a negative FD upon dup failure
* src/patch.c (open_outfile): If dup fails, don't clobber its
errno value by calling fdopen with -1.
---
src/patch.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/patch.c b/src/patch.c
index 44b6571..d73aaaf 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -1466,9 +1466,12 @@ open_outfile (char const *name)
return create_output_file (name, 0);
else
{
+ FILE *ofp;
int stdout_dup = dup (fileno (stdout));
- FILE *ofp = fdopen (stdout_dup, "a");
- if (stdout_dup == -1 || ! ofp)
+ if (stdout_dup == -1)
+ pfatal ("Failed to duplicate standard output");
+ ofp = fdopen (stdout_dup, "a");
+ if (! ofp)
pfatal ("Failed to duplicate standard output");
if (dup2 (fileno (stderr), fileno (stdout)) == -1)
pfatal ("Failed to redirect messages to standard error");
--
1.7.5.2.585.gfbd48