From: Junio C Hamano Date: Thu, 13 Jan 2022 21:37:08 GMT Subject: Re: [PATCH 2/3] reftable: remove unreachable "return" statements Message-ID: In-Reply-To: <9ce034fd-b696-60d2-c292-98285aff180a@kdbg.org> Johannes Sixt writes: > Why not just sidestep the problematic case: > > diff --git a/reftable/refname.c b/reftable/refname.c > index 9573496932..4f89956187 100644 > --- a/reftable/refname.c > +++ b/reftable/refname.c > @@ -120,17 +120,17 @@ static int modification_has_ref_with_prefix(struct modification *mod, > static int validate_refname(const char *name) > { > while (1) { > char *next = strchr(name, '/'); > if (!*name) { > return REFTABLE_REFNAME_ERROR; > } > if (!next) { > - return 0; > + break; > } > if (next - name == 0 || (next - name == 1 && *name == '.') || > (next - name == 2 && name[0] == '.' && name[1] == '.')) > return REFTABLE_REFNAME_ERROR; > name = next + 1; > } > return 0; > } > > Sure, there are returns in the loop, but they are clearly error cases. > The regular exit is now at the end of the function. ;-)