{"thread":{"id":"27468","subject":"[PATCH] Fix useless comparison bug","startedAt":"2011-05-26T14:01:52Z","lastAt":"2011-05-26T14:01:52Z","messageCount":1,"participants":["Chris Wilson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"168766","messageId":"20110526140152.GA19748@localhost","threadId":"27468","inReplyTo":null,"subject":"[PATCH] Fix useless comparison bug","fromName":"Chris Wilson","fromEmail":"cwilson@vigilantsw.com","sentAt":"2011-05-26T14:01:52Z","receivedAt":"2011-05-26T14:01:52Z","isPatch":true,"sender":{"key":"cwilson@vigilantsw.com","avatar":null},"body":"The variable 'actual' was declared with a size_t type. In this line:\n\n  actual = read_in_full(fd, buf, sz);\n\nread_in_full returns a ssize_t type. Since size_t is unsigned and\nssize_t is signed, the value is implicitly converted from a signed\ntype to an unsigned type. That makes this comparison useless,\n\n  if (actual < 0)\n    die_errno(\"index-stream: reading input\");\n\nas it will always be false. This means, on an error path, git will\ncontinue when it should die gracefully.\n\nThis bug was introduced in 4dd1fbc.\n\nSigned-off-by: Chris Wilson <cwilson@vigilantsw.com>\n---\n\nHi Folks,\n\nSentry found this committed in last nights snapshot.\n\nChris Wilson\nhttp://vigilantsw.com/\nVigilant Software\n\n sha1_file.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 064a330..c251af8 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2704,7 +2704,7 @@ static int index_stream(unsigned char *sha1, int fd, size_t size,\n        while (size) {\n                char buf[10240];\n                size_t sz = size < sizeof(buf) ? size : sizeof(buf);\n-               size_t actual;\n+               ssize_t actual;\n\n                actual = read_in_full(fd, buf, sz);\n                if (actual < 0)\n-- \n1.6.3.3\n"}]}