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

Re: [PATCH] add_pending_object_with_path(): work around "gcc -O3" complaint

From
Jeff King <peff@peff.net>
Date
Jun 10, 2021, 13:11 UTC
Message-ID
<YMIPb+9e2PtaLZhl@coredump.intra.peff.net>
In-Reply-To
<YMIOY6Hp6//yGrFm@coredump.intra.peff.net>
On Thu, Jun 10, 2021 at 09:06:44AM -0400, Jeff King wrote:
Show 9 quoted lines
> We can work around this by replacing our "did we hit the trailing NUL"
> subscript dereference with a length check. We do not even have to pay
> the cost for an extra strlen(), as we can pass our new length into
> interpret_branch_name(), which was converting our "0" into a call to
> strlen() anyway.
> [...]
> -		if (0 < len && name[len] && buf.len)
> +		if (0 < len && len < namelen && buf.len)
>  			strbuf_addstr(&buf, name + len);

I guess another option would be to drop the check entirely. It is only protecting us from calling strbuf_addstr() with an empty string, which is a noop anyway (it would not even cause a useless allocation, since we know that buf is non-empty, and that it won't need to grow).

I think I still prefer my original solution, though.
-Peff
Previous: Jeff KingNext: Junio C Hamano
Message 2 of 3 in “add_pending_object_with_path(): work around "gcc -O3" complaint”
  1. add_pending_object_with_path(): work around "gcc -O3" complaintJeff King, Jun 10, 2021
  2. Jeff KingJun 10, 2021
  3. Junio C HamanoJun 11, 2021

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.