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

[PATCH] refs.c: fix fread error handling

From
John Keeping <john@keeping.me.uk>
Date
Mar 23, 2013, 17:16 UTC
Message-ID
<ba7cd71b0ac9a885bd894a0bed608cf682afed6d.1364058591.git.john@keeping.me.uk>
fread returns the number of items read, with no special error return.

Commit 98f85ff (reflog: add for_each_reflog_ent_reverse() API - 2013-03-08) introduced a call to fread which checks for an error with "nread < 0" which is tautological since nread is unsigned. The correct check in this case (which tries to read a single item) is "nread != 1".

Signed-off-by: John Keeping <john@keeping.me.uk>
---
I found this because Clang generated a tautological comparison warning
on this line.
 refs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/refs.c b/refs.c
index 56cc93d..de2d8eb 100644
--- a/refs.c
+++ b/refs.c
@@ -2399,7 +2399,7 @@ int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn, void
 			return error("cannot seek back reflog for %s: %s",
 				     refname, strerror(errno));
 		nread = fread(buf, cnt, 1, logfp);
-		if (nread < 0)
+		if (nread != 1)
 			return error("cannot read %d bytes from reflog for %s: %s",
 				     cnt, refname, strerror(errno));
 		pos -= cnt;
-- 
1.8.2.411.g65a544e
Next: Junio C Hamano
Message 1 of 2 in “refs.c: fix fread error handling”
  1. refs.c: fix fread error handlingJohn Keeping, Mar 23, 2013
  2. Junio C HamanoMar 24, 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.