git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] wt-status: use strncmp() for length-limited string comparison

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Nov 25, 2015, 10:29 UTC
Message-ID
<vpqtwoawewc.fsf@anie.imag.fr>
In-Reply-To
<20151125091503.GA1779@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 20 quoted lines
>> diff --git a/wt-status.c b/wt-status.c
>> index 435fc28..96a731e 100644
>> --- a/wt-status.c
>> +++ b/wt-status.c
>> @@ -1317,14 +1317,14 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
>>  	target += strlen(" to ");
>>  	strbuf_reset(&cb->buf);
>>  	hashcpy(cb->nsha1, nsha1);
>> -	for (end = target; *end && *end != '\n'; end++)
>> -		;
>> -	if (!memcmp(target, "HEAD", end - target)) {
>> +	if (skip_prefix(target, "HEAD", &end) && (!*end || *end == '\n')) {
>>  		/* HEAD is relative. Resolve it to the right reflog entry. */
>>  		strbuf_addstr(&cb->buf,
>>  			      find_unique_abbrev(nsha1, DEFAULT_ABBREV));
>>  		return 1;
>>  	}
>
> Yeah, I think parsing left-to-right like this makes things much more
> obvious.
Agreed.
Show 5 quoted lines
>> +	for (end = target; *end && *end != '\n'; end++)
>> +		;
>
> This loop (which I know you just moved, not wrote) is basically
> strchrnul, isn't it? That might be more readable.
Agreed too.
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Jeff KingNext: René Scharfe
Message 5 of 8 in “wt-status: use strncmp() for length-limited string comparison”
  1. wt-status: use strncmp() for length-limited string comparisonRené Scharfe, Nov 6, 2015
  2. Jeff KingNov 24, 2015
  3. René ScharfeNov 25, 2015
  4. Jeff KingNov 25, 2015
  5. Matthieu MoyNov 25, 2015
  6. wt-status: correct and simplify check for detached HEADRené Scharfe, Nov 25, 2015
  7. Matthieu MoyNov 25, 2015
  8. Jeff KingNov 28, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.