git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] refs.c: fix fread error handling
@ 2013-03-23 17:16 John Keeping
  2013-03-24  6:50 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: John Keeping @ 2013-03-23 17:16 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, John Keeping

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] refs.c: fix fread error handling
  2013-03-23 17:16 [PATCH] refs.c: fix fread error handling John Keeping
@ 2013-03-24  6:50 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2013-03-24  6:50 UTC (permalink / raw)
  To: John Keeping; +Cc: git

Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-03-24  6:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-23 17:16 [PATCH] refs.c: fix fread error handling John Keeping
2013-03-24  6:50 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).