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

[PATCH] Fix useless comparison bug

From
CWChris Wilson <cwilson@vigilantsw.com>
Date
May 26, 2011, 14:01 UTC
Message-ID
<20110526140152.GA19748@localhost>
The variable 'actual' was declared with a size_t type. In this line:
  actual = read_in_full(fd, buf, sz);

read_in_full returns a ssize_t type. Since size_t is unsigned and ssize_t is signed, the value is implicitly converted from a signed type to an unsigned type. That makes this comparison useless,

  if (actual < 0)
    die_errno("index-stream: reading input");

as it will always be false. This means, on an error path, git will continue when it should die gracefully.

This bug was introduced in 4dd1fbc.
Signed-off-by: Chris Wilson <cwilson@vigilantsw.com>
---
Hi Folks,
Sentry found this committed in last nights snapshot.

Chris Wilson http://vigilantsw.com/ Vigilant Software

 sha1_file.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index 064a330..c251af8 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2704,7 +2704,7 @@ static int index_stream(unsigned char *sha1, int fd, size_t size,
        while (size) {
                char buf[10240];
                size_t sz = size < sizeof(buf) ? size : sizeof(buf);
-               size_t actual;
+               ssize_t actual;

                actual = read_in_full(fd, buf, sz);
                if (actual < 0)
-- 
1.6.3.3
Message 1 of 1 in “Fix useless comparison bug”
  1. Fix useless comparison bugChris Wilson, May 26, 2011

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.