From: Junio C Hamano Date: Wed, 23 Oct 2019 03:38:59 GMT Subject: Re: [PATCH v3 2/2] git_path(): handle `.lock` files correctly Message-ID: In-Reply-To: <20191022160105.GE4348@szeder.dev> SZEDER Gábor writes: >> + char *base = buf->buf + git_dir_len, *base2 = NULL; >> + >> + if (ends_with(base, ".lock")) >> + base = base2 = xstrndup(base, strlen(base) - 5); > > Hm, this adds the magic number 5 and calls strlen(base) twice, because > ends_with() calls strip_suffix(), which calls strlen(). Calling > strip_suffix() directly would allow us to avoid the magic number and > the second strlen(): > > size_t len; > if (strip_suffix(base, ".lock", &len)) > base = base2 = xstrndup(base, len); Makes sense, and is easy to squash in.