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

[PATCH 2/2] do not check truth value of flex arrays

From
Jeff King <peff@peff.net>
Date
Jan 28, 2015, 17:58 UTC
Message-ID
<20150128175850.GB8172@peff.net>
In-Reply-To
<20150128175314.GA13362@peff.net>

There is no point in checking "!ref->name" when ref is a "struct ref". The name field is a flex-array, and there always has a non-zero address. This is almost certainly not hurting anything, but it does cause clang-3.6 to complain.

Signed-off-by: Jeff King <peff@peff.net>
---
Note that even if "ref" is NULL, this is still going to be
"0+offsetof(name)". So short of unsigned pointer wrap-around, I do not
think this check can ever do anything.
 remote-curl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/remote-curl.c b/remote-curl.c
index dd63bc2..515ac9b 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -760,7 +760,7 @@ static int fetch_git(struct discovery *heads,
 
 	for (i = 0; i < nr_heads; i++) {
 		struct ref *ref = to_fetch[i];
-		if (!ref->name || !*ref->name)
+		if (!*ref->name)
 			die("cannot fetch by sha1 over smart http");
 		packet_buf_write(&preamble, "%s %s\n",
 				 sha1_to_hex(ref->old_sha1), ref->name);
-- 
2.3.0.rc1.287.g761fd19
Previous: Junio C Hamano
Message 6 of 6 in “silence clang-3.6 warnings”
  1. 0/2 silence clang-3.6 warningsJeff King, Jan 28, 2015
  2. 1/2 read_and_strip_branch: fix typo'd address-of operatorJeff King, Jan 28, 2015
  3. Junio C HamanoJan 28, 2015
  4. Jeff KingJan 28, 2015
  5. Junio C HamanoJan 29, 2015
  6. 2/2 do not check truth value of flex arraysJeff King, Jan 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.