{"thread":{"id":"33272","subject":"[PATCH] refs.c: fix fread error handling","startedAt":"2013-03-23T17:16:46Z","lastAt":"2013-03-24T06:50:56Z","messageCount":2,"participants":["John Keeping","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"212060","messageId":"ba7cd71b0ac9a885bd894a0bed608cf682afed6d.1364058591.git.john@keeping.me.uk","threadId":"33272","inReplyTo":null,"subject":"[PATCH] refs.c: fix fread error handling","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2013-03-23T17:16:46Z","receivedAt":"2013-03-23T17:16:46Z","isPatch":true,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"fread returns the number of items read, with no special error return.\n\nCommit 98f85ff (reflog: add for_each_reflog_ent_reverse() API -\n2013-03-08) introduced a call to fread which checks for an error with\n\"nread < 0\" which is tautological since nread is unsigned.  The correct\ncheck in this case (which tries to read a single item) is \"nread != 1\".\n\nSigned-off-by: John Keeping <john@keeping.me.uk>\n---\nI found this because Clang generated a tautological comparison warning\non this line.\n\n refs.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/refs.c b/refs.c\nindex 56cc93d..de2d8eb 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2399,7 +2399,7 @@ int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn, void\n \t\t\treturn error(\"cannot seek back reflog for %s: %s\",\n \t\t\t\t     refname, strerror(errno));\n \t\tnread = fread(buf, cnt, 1, logfp);\n-\t\tif (nread < 0)\n+\t\tif (nread != 1)\n \t\t\treturn error(\"cannot read %d bytes from reflog for %s: %s\",\n \t\t\t\t     cnt, refname, strerror(errno));\n \t\tpos -= cnt;\n-- \n1.8.2.411.g65a544e\n"},{"id":"212078","messageId":"7vmwtt2svj.fsf@alter.siamese.dyndns.org","threadId":"33272","inReplyTo":"ba7cd71b0ac9a885bd894a0bed608cf682afed6d.1364058591.git.john@keeping.me.uk","subject":"Re: [PATCH] refs.c: fix fread error handling","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-03-24T06:50:56Z","receivedAt":"2013-03-24T06:50:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.\n"}]}