threads / patch / 33272

patchrefs.c: fix fread error handling

Subject: [PATCH] refs.c: fix fread error handling

## tl;dr

2 messages between Mar 23, 2013 and Mar 24, 2013. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

John Keeping· Mar 23, 2013, 17:16 UTC · lore
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(-)
Show changes to refs.c +1 −1
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

← back to recent threads