From: Christian Couder Date: Thu, 10 Aug 2017 15:58:38 GMT Subject: Re: [PATCH] apply: remove prefix_length member from apply_state Message-ID: In-Reply-To: <24fb9d9c-0b1c-4aaa-7d89-12d322066cff@web.de> On Wed, Aug 9, 2017 at 5:54 PM, René Scharfe wrote: > Use a NULL-and-NUL check to see if we have a prefix and consistently use > C string functions on it instead of storing its length in a member of > struct apply_state. This avoids strlen() calls and simplifies the code. This looks like a good idea. > @@ -2088,10 +2087,9 @@ static int use_patch(struct apply_state *state, struct patch *p) > int i; > > /* Paths outside are not touched regardless of "--include" */ > - if (0 < state->prefix_length) { > - int pathlen = strlen(pathname); > - if (pathlen <= state->prefix_length || > - memcmp(state->prefix, pathname, state->prefix_length)) > + if (state->prefix && *state->prefix) { > + const char *rest; > + if (!skip_prefix(pathname, state->prefix, &rest) || !*rest) > return 0; > } Yeah, or maybe declare "const char *rest;" just after "int i;" and then use: if (state->prefix && *state->prefix && (!skip_prefix(pathname, state->prefix, &rest) || !*rest)) return 0;