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

Re: [PATCH 3/3] builtin/apply: tighten (dis)similarity index parsing

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 3, 2013, 20:50 UTC
Message-ID
<7vd2wh86m4.fsf@alter.siamese.dyndns.org>
In-Reply-To
<2cac21192f79f9fbb5822417775954eba29064fa.1359901732.git.john@keeping.me.uk>
John Keeping <john@keeping.me.uk> writes:
Show 25 quoted lines
> diff --git a/builtin/apply.c b/builtin/apply.c
> index 6c11e8b..4745e75 100644
> --- a/builtin/apply.c
> +++ b/builtin/apply.c
> @@ -1041,15 +1041,17 @@ static int gitdiff_renamedst(const char *line, struct patch *patch)
>  
>  static int gitdiff_similarity(const char *line, struct patch *patch)
>  {
> -	if ((patch->score = strtoul(line, NULL, 10)) == ULONG_MAX)
> -		patch->score = 0;
> +	unsigned long val = strtoul(line, NULL, 10);
> +	if (val <= 100)
> +		patch->score = val;
>  	return 0;
>  }
>  
>  static int gitdiff_dissimilarity(const char *line, struct patch *patch)
>  {
> -	if ((patch->score = strtoul(line, NULL, 10)) == ULONG_MAX)
> -		patch->score = 0;
> +	unsigned long val = strtoul(line, NULL, 10);
> +	if (val <= 100)
> +		patch->score = val;
>  	return 0;
>  }

This makes sort of sense; .score is used only for display and not for making any decision, so as long as you know it is initialized to zero when the call to this function is made, it should be OK.

Thanks.
Previous: John KeepingNext: Antoine Pelisse
Message 19 of 20 in “Make Git compile warning-free with Clang”
  1. 0/3 Make Git compile warning-free with ClangJohn Keeping, Feb 3, 2013
  2. 1/3 fix clang -Wtautological-compare with unsigned enumJohn Keeping, Feb 3, 2013
  3. Jonathan NiederFeb 3, 2013
  4. 2/3 combine-diff: suppress a clang warningJohn Keeping, Feb 3, 2013
  5. Tay Ray ChuanFeb 3, 2013
  6. John KeepingFeb 3, 2013
  7. Junio C HamanoFeb 3, 2013
  8. John KeepingFeb 3, 2013
  9. Junio C HamanoFeb 3, 2013
  10. John KeepingFeb 3, 2013
  11. Junio C HamanoFeb 4, 2013
  12. t4038: add tests for "diff --cc --raw <trees>"John Keeping, Feb 5, 2013
  13. Junio C HamanoFeb 5, 2013
  14. t4038: add tests for "diff --cc --raw <trees>"John Keeping, Feb 5, 2013
  15. Junio C HamanoFeb 5, 2013
  16. Miles BaderFeb 7, 2013
  17. John KeepingFeb 7, 2013
  18. 3/3 builtin/apply: tighten (dis)similarity index parsingJohn Keeping, Feb 3, 2013
  19. Junio C HamanoFeb 3, 2013
  20. Antoine PelisseFeb 3, 2013

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.