From 892e723afd2b5696e4d75280e730bf9f1ea92329 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 28 Mar 2017 15:45:25 -0400 Subject: do not check odb_mkstemp return value for errors The odb_mkstemp function does not return an error; it dies on failure instead. But many of its callers compare the resulting descriptor against -1 and die themselves. Mostly this is just pointless, but it does raise a question when looking at the callers: if they show the results of the "template" buffer after a failure, what's in it? The answer is: it doesn't matter, because it cannot happen. So let's make that clear by removing the bogus error checks. In bitmap_writer_finish(), we can drop the error-handling code entirely. In the other two cases, it's shared with the open() in another code path; we can just move the error-check next to that open() call. And while we're at it, let's flesh out the function's docstring a bit to make the error behavior clear. Signed-off-by: Jeff King --- pack-write.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pack-write.c') diff --git a/pack-write.c b/pack-write.c index c057513f1..485080a31 100644 --- a/pack-write.c +++ b/pack-write.c @@ -77,9 +77,9 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec } else { unlink(index_name); fd = open(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600); + if (fd < 0) + die_errno("unable to create '%s'", index_name); } - if (fd < 0) - die_errno("unable to create '%s'", index_name); f = sha1fd(fd, index_name); } -- cgit v1.2.1