Skip to contentSkip to conversation

Fix useless comparison bug

PATCH New Chris Wilson 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix useless comparison bug

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.

---

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(-)
sha1_file.c +1 -1
index 064a330..c251af8 100644
@@ -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)
Signature · 1 line
1.6.3.3