Re: [PATCH v6 20/42] fetch.c: clear errno before calling functions that might set it
From: Ronnie Sahlberg <hidden>
Date: 2016-06-15 23:00:58
Fixed. Thanks. On Thu, May 1, 2014 at 9:11 PM, Eric Sunshine [off-list ref] wrote:
On Thu, May 1, 2014 at 4:37 PM, Ronnie Sahlberg [off-list ref] wrote:quoted
In s_update_ref there are two calls that when they fail we return an error based on the errno value. In particular we want to return a specific error if ENOTDIR happened. Both these functions do have failure modes where they may return an error without updating errno, in which case a previous and unrelated ENOTDIT may cause us to return the wrong error. Clear errno befores/ENOTDIT/ENOTDIR/quoted
calling any functions if we check errno afterwards. Also skip initializing a static variable to 0. Statics live in .bss and are all automatically initialized to 0. Signed-off-by: Ronnie Sahlberg <redacted> --- builtin/fetch.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)diff --git a/builtin/fetch.c b/builtin/fetch.c index 55f457c..a93c893 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c@@ -44,7 +44,7 @@ static struct transport *gtransport; static struct transport *gsecondary; static const char *submodule_prefix = ""; static const char *recurse_submodules_default; -static int shown_url = 0; +static int shown_url; static int option_parse_recurse_submodules(const struct option *opt, const char *arg, int unset)@@ -382,6 +382,8 @@ static int s_update_ref(const char *action, if (!rla) rla = default_rla.buf; snprintf(msg, sizeof(msg), "%s: %s", rla, action); + + errno = 0; lock = lock_any_ref_for_update(ref->name, check_old ? ref->old_sha1 : NULL, 0, NULL); --2.0.0.rc1.351.g4d2c8e4