All of lore.kernel.org
 help / color / mirror / Atom feed
From: cuiweixie <cuiweixie@gmail.com>
To: git@vger.kernel.org
Cc: cuiweixie <cuiweixie@gmail.com>
Subject: [PATCH] fetch: fix wrong evaluation order in URL trailing-slash trimming
Date: Mon, 23 Feb 2026 18:07:28 +0800	[thread overview]
Message-ID: <20260223100728.79928-1-cuiweixie@gmail.com> (raw)

if i == -1, url[i] will be UB.

Signed-off-by: cuiweixie <cuiweixie@gmail.com>
---
 builtin/fetch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/fetch.c b/builtin/fetch.c
index a3bc7e9380..306138c6e5 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -722,7 +722,7 @@ static void display_state_init(struct display_state *display_state, struct ref *
 		display_state->url = xstrdup("foreign");
 
 	display_state->url_len = strlen(display_state->url);
-	for (i = display_state->url_len - 1; display_state->url[i] == '/' && 0 <= i; i--)
+	for (i = display_state->url_len - 1; 0 <= i && display_state->url[i] == '/'; i--)
 		;
 	display_state->url_len = i + 1;
 	if (4 < i && !strncmp(".git", display_state->url + i - 3, 4))
-- 
2.39.5 (Apple Git-154)


             reply	other threads:[~2026-02-23 10:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-23 10:07 cuiweixie [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-02-25  2:00 [PATCH] fetch: fix wrong evaluation order in URL trailing-slash trimming cui via GitGitGadget
2026-02-25 14:10 ` Jeff King
2026-02-25 15:36   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260223100728.79928-1-cuiweixie@gmail.com \
    --to=cuiweixie@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.