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

[PATCH] open_istream: remove unneeded check for null pointer

From
Stefan Beller <stefanbeller@googlemail.com>
Date
Jul 23, 2013, 13:16 UTC
Message-ID
<1374585364-12159-1-git-send-email-stefanbeller@googlemail.com>

'st' is allocated via xmalloc a few lines before and passed to the stream opening functions. The xmalloc function is written in a way that either 'st' is allocated valid memory or xmalloc already dies. The function calls to open_istream_* do not change 'st', as the pointer is passed by reference and not a pointer of a pointer.

Hence 'st' cannot be null at that part of the code.
Signed-off-by: Stefan Beller <stefanbeller@googlemail.com>
---
 streaming.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/streaming.c b/streaming.c
index acc07a6..debe904 100644
--- a/streaming.c
+++ b/streaming.c
@@ -144,17 +144,17 @@ struct git_istream *open_istream(const unsigned char *sha1,
 
 	st = xmalloc(sizeof(*st));
 	if (open_istream_tbl[src](st, &oi, real, type)) {
 		if (open_istream_incore(st, &oi, real, type)) {
 			free(st);
 			return NULL;
 		}
 	}
-	if (st && filter) {
+	if (filter) {
 		/* Add "&& !is_null_stream_filter(filter)" for performance */
 		struct git_istream *nst = attach_stream_filter(st, filter);
 		if (!nst)
 			close_istream(st);
 		st = nst;
 	}
 
 	*size = st->size;
-- 
1.8.3.3.1135.ge2c9e63
Message 1 of 1 in “open_istream: remove unneeded check for null pointer”
  1. open_istream: remove unneeded check for null pointerStefan Beller, Jul 23, 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.