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

Re: [PATCH 1/2] dir.c: avoid gcc warning

From
Junio C Hamano <gitster@pobox.com>
Date
May 6, 2022, 20:21 UTC
Message-ID
<xmqqy1zejtte.fsf@gitster.g>
In-Reply-To
<cd50ec73ddafaaeba04298ae79cbf625cc0d7697.1651859773.git.git@grubix.eu>
Michael J Gruber <git@grubix.eu> writes:
> Related to -Wstringop-overread.
>
> In fact, this may be a false positive, but reading until the correct end
> is desirable here anyways.

But the correct end is start + (end - start), not start + (end - start + 1), isn't it? We've stripped trailing junk like /.git and end is point at one byte beyond the end of URL to the repository.

E.g. for "https://auth@host/", we have advanced start to point at "h" at the beginning of "host", and we have moved end back from pointing at the NUL at the end to point at "/" at the end of "host/".

We are trying to make sure that the resulting "host" string between start and end do not have a slash to apply this special case.

If the original URL were "https://auth@host:4321/", the end points at "/" at the end of "host:4321/", making the string to be checked to "host:4321" and we are trying to see it has no '/' in it (which is the case). By extending the string by one, memchr() will see the '/' at the end that is outside.

This seems to be a behaviour breaking change and I am not sure what we are trying to achieve with it. Is this a suggestion made by a broken compiler you have, or something?

Puzzled....
Show 18 quoted lines
> Signed-off-by: Michael J Gruber <git@grubix.eu>
> ---
>  dir.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/dir.c b/dir.c
> index 26c4d141ab..32fcaae4c0 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -3145,7 +3145,7 @@ char *git_url_basename(const char *repo, int is_bundle, int is_bare)
>  	 * result in a dir '2222' being guessed due to backwards
>  	 * compatibility.
>  	 */
> -	if (memchr(start, '/', end - start) == NULL
> +	if (memchr(start, '/', end - start + 1) == NULL
>  	    && memchr(start, ':', end - start) != NULL) {
>  		ptr = end;
>  		while (start < ptr && isdigit(ptr[-1]) && ptr[-1] != ':')
Previous: Michael J GruberNext: Taylor Blau
Message 3 of 38 in “quell a few gcc warnings”
  1. 0/2 quell a few gcc warningsMichael J Gruber, May 6, 2022
  2. 1/2 dir.c: avoid gcc warningMichael J Gruber, May 6, 2022
  3. Junio C HamanoMay 6, 2022
  4. Taylor BlauMay 9, 2022
  5. Carlo Marcelo Arenas BelónMay 7, 2022
  6. 2/2 http.c: avoid gcc warningMichael J Gruber, May 6, 2022
  7. Junio C HamanoMay 6, 2022
  8. http.c: clear the 'finished' member once we are done with itJunio C Hamano, May 6, 2022
  9. Carlo Marcelo Arenas BelónMay 7, 2022
  10. Junio C HamanoMay 7, 2022
  11. Carlo ArenasMay 7, 2022
  12. Johannes SchindelinMay 23, 2022
  13. Junio C HamanoMay 23, 2022
  14. Junio C HamanoMay 23, 2022
  15. Johannes SchindelinMay 23, 2022
  16. Junio C HamanoMay 24, 2022
  17. Daniel StenbergMay 24, 2022
  18. Johannes SchindelinMay 24, 2022
  19. Junio C HamanoMay 24, 2022
  20. Daniel StenbergMay 26, 2022
  21. Johannes SchindelinMay 24, 2022
  22. Junio C HamanoMay 24, 2022
  23. Carlo Marcelo Arenas BelónMay 24, 2022
  24. Ævar Arnfjörð BjarmasonMay 24, 2022
  25. Junio C HamanoMay 24, 2022
  26. Michael J GruberMay 25, 2022
  27. Ævar Arnfjörð BjarmasonMay 25, 2022
  28. Junio C HamanoMay 24, 2022
  29. Junio C HamanoMay 24, 2022
  30. Carlo ArenasMay 25, 2022
  31. Ævar Arnfjörð BjarmasonMay 24, 2022
  32. Junio C HamanoMay 24, 2022
  33. Johannes SchindelinMay 25, 2022
  34. Junio C HamanoMay 25, 2022
  35. Carlo Marcelo Arenas BelónMay 6, 2022
  36. detect-compiler: make detection independent of localeMichael J Gruber, May 9, 2022
  37. Junio C HamanoMay 9, 2022
  38. rsbecker@nexbridge.comMay 9, 2022

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.