{"thread":{"id":"8167","subject":"BUG in fixup_pack_header_footer(...) / pack-write.c checksum error never raised","startedAt":"2007-05-15T11:47:18Z","lastAt":"2007-05-15T23:24:35Z","messageCount":7,"participants":["Paolo Teti","Johan Herland","Dana How","Shawn O. Pearce"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"42214","messageId":"34a7ae040705150447k2e770b5ag3629632f61b813a0@mail.gmail.com","threadId":"8167","inReplyTo":null,"subject":"BUG in fixup_pack_header_footer(...) / pack-write.c checksum error never raised","fromName":"Paolo Teti","fromEmail":"paolo.teti@gmail.com","sentAt":"2007-05-15T11:47:18Z","receivedAt":"2007-05-15T11:47:18Z","isPatch":false,"sender":{"key":"paolo.teti@gmail.com","avatar":null},"body":"In fixup_pack_header_footer(...) file pack-write.c\nWe have to change the size_t value returned by\nxread() in ssize_t, otherwise the next check on negative\nvalues has no sense.\n\nsize_t is an unsigned type!\n\nI can't write now a patch because I'm on a customer site\nand I can't install GIT...\n\nI'm just looking at the souce code using gitweb during a coffebreak.\n\nSomeone can fix it?..\n\nPao\n"},{"id":"42216","messageId":"200705151439.25871.johan@herland.net","threadId":"8167","inReplyTo":"34a7ae040705150447k2e770b5ag3629632f61b813a0@mail.gmail.com","subject":"[PATCH] Fix signedness on return value from xread()","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2007-05-15T12:39:25Z","receivedAt":"2007-05-15T12:39:25Z","isPatch":true,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"The return value from xread() is ssize_t. \nPaolo Teti <paolo.teti@gmail.com> pointed out that in this case, the \nsigned return value was assigned to an unsigned type (size_t). This patch \nfixes that.\n\nSigned-off-by: Johan Herland <johan@herland.net>\n---\n\nUsing this as an opportunity to get used to sending patches... :)\n\nIs this what you were looking for, Paolo?\n\n pack-write.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/pack-write.c b/pack-write.c\nindex de72f44..ae2e481 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -25,7 +25,7 @@ void fixup_pack_header_footer(int pack_fd,\n \n \tbuf = xmalloc(buf_sz);\n \tfor (;;) {\n-\t\tsize_t n = xread(pack_fd, buf, buf_sz);\n+\t\tssize_t n = xread(pack_fd, buf, buf_sz);\n \t\tif (!n)\n \t\t\tbreak;\n \t\tif (n < 0)\n-- \n1.5.1.4\n"},{"id":"42217","messageId":"34a7ae040705150548l666cdff8o5fe34a1366cec013@mail.gmail.com","threadId":"8167","inReplyTo":"200705151439.25871.johan@herland.net","subject":"Re: [PATCH] Fix signedness on return value from xread()","fromName":"Paolo Teti","fromEmail":"paolo.teti@gmail.com","sentAt":"2007-05-15T12:48:43Z","receivedAt":"2007-05-15T12:48:43Z","isPatch":true,"sender":{"key":"paolo.teti@gmail.com","avatar":null},"body":"2007/5/15, Johan Herland <johan@herland.net>:\n> Using this as an opportunity to get used to sending patches... :)\n>\n> Is this what you were looking for, Paolo?\n>\n\nYes Johan your patch fixes the bug.\n\nThanks\n"},{"id":"42218","messageId":"200705151449.22744.johan@herland.net","threadId":"8167","inReplyTo":"200705151439.25871.johan@herland.net","subject":"[PATCH] Ensure return value from xread() is always stored into an ssize_t","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2007-05-15T12:49:22Z","receivedAt":"2007-05-15T12:49:22Z","isPatch":true,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"This patch fixes all calls to xread() where the return value is not \nstored into an ssize_t. The patch should not have any effect whatsoever, \nother than putting better/more appropriate type names on variables.\n\nSigned-off-by: Johan Herland <johan@herland.net>\n---\n\nFeel free to ignore this patch as it may be argued that it needlessly \ntouches a lot of code, without having much (if any) positive effect \nat all.\n\n builtin-apply.c          |    4 ++--\n builtin-bundle.c         |    2 +-\n builtin-fetch--tool.c    |    4 ++--\n builtin-unpack-objects.c |    2 +-\n combine-diff.c           |    2 +-\n copy.c                   |    3 +--\n diff.c                   |    2 +-\n imap-send.c              |    2 +-\n index-pack.c             |    2 +-\n pkt-line.c               |    4 ++--\n sha1_file.c              |    2 +-\n ssh-upload.c             |    2 +-\n 12 files changed, 15 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex 8b8705a..0399743 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -185,7 +185,7 @@ static void *read_patch_file(int fd, unsigned long *sizep)\n \tvoid *buffer = xmalloc(alloc);\n \n \tfor (;;) {\n-\t\tint nr = alloc - size;\n+\t\tssize_t nr = alloc - size;\n \t\tif (nr < 1024) {\n \t\t\talloc += CHUNKSIZE;\n \t\t\tbuffer = xrealloc(buffer, alloc);\n@@ -1468,7 +1468,7 @@ static int read_old_data(struct stat *st, const char *path, char **buf_p, unsign\n \t\t\treturn error(\"unable to open %s\", path);\n \t\tgot = 0;\n \t\tfor (;;) {\n-\t\t\tint ret = xread(fd, buf + got, size - got);\n+\t\t\tssize_t ret = xread(fd, buf + got, size - got);\n \t\t\tif (ret <= 0)\n \t\t\t\tbreak;\n \t\t\tgot += ret;\ndiff --git a/builtin-bundle.c b/builtin-bundle.c\nindex d1635a0..306ad29 100644\n--- a/builtin-bundle.c\n+++ b/builtin-bundle.c\n@@ -48,7 +48,7 @@ static int read_string(int fd, char *buffer, int size)\n {\n \tint i;\n \tfor (i = 0; i < size - 1; i++) {\n-\t\tint count = xread(fd, buffer + i, 1);\n+\t\tssize_t count = xread(fd, buffer + i, 1);\n \t\tif (count < 0)\n \t\t\treturn error(\"Read error: %s\", strerror(errno));\n \t\tif (count == 0) {\ndiff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c\nindex 2065466..12adb38 100644\n--- a/builtin-fetch--tool.c\n+++ b/builtin-fetch--tool.c\n@@ -6,11 +6,11 @@\n \n static char *get_stdin(void)\n {\n-\tint offset = 0;\n+\tsize_t offset = 0;\n \tchar *data = xmalloc(CHUNK_SIZE);\n \n \twhile (1) {\n-\t\tint cnt = xread(0, data + offset, CHUNK_SIZE);\n+\t\tssize_t cnt = xread(0, data + offset, CHUNK_SIZE);\n \t\tif (cnt < 0)\n \t\t\tdie(\"error reading standard input: %s\",\n \t\t\t    strerror(errno));\ndiff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c\nindex 2bbda67..a6ff62f 100644\n--- a/builtin-unpack-objects.c\n+++ b/builtin-unpack-objects.c\n@@ -34,7 +34,7 @@ static void *fill(int min)\n \t\toffset = 0;\n \t}\n \tdo {\n-\t\tint ret = xread(0, buffer + len, sizeof(buffer) - len);\n+\t\tssize_t ret = xread(0, buffer + len, sizeof(buffer) - len);\n \t\tif (ret <= 0) {\n \t\t\tif (!ret)\n \t\t\t\tdie(\"early EOF\");\ndiff --git a/combine-diff.c b/combine-diff.c\nindex cff9c5d..ea3ca5f 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -714,7 +714,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \t\t\tresult_size = len;\n \t\t\tresult = xmalloc(len + 1);\n \t\t\twhile (sz < len) {\n-\t\t\t\tint done = xread(fd, result+sz, len-sz);\n+\t\t\t\tssize_t done = xread(fd, result+sz, len-sz);\n \t\t\t\tif (done == 0)\n \t\t\t\t\tbreak;\n \t\t\t\tif (done < 0)\ndiff --git a/copy.c b/copy.c\nindex 08a3d38..d340bb2 100644\n--- a/copy.c\n+++ b/copy.c\n@@ -3,10 +3,9 @@\n int copy_fd(int ifd, int ofd)\n {\n \twhile (1) {\n-\t\tint len;\n \t\tchar buffer[8192];\n \t\tchar *buf = buffer;\n-\t\tlen = xread(ifd, buffer, sizeof(buffer));\n+\t\tssize_t len = xread(ifd, buffer, sizeof(buffer));\n \t\tif (!len)\n \t\t\tbreak;\n \t\tif (len < 0) {\ndiff --git a/diff.c b/diff.c\nindex 8354e71..33297aa 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1411,7 +1411,7 @@ static int populate_from_stdin(struct diff_filespec *s)\n #define INCREMENT 1024\n \tchar *buf;\n \tunsigned long size;\n-\tint got;\n+\tssize_t got;\n \n \tsize = 0;\n \tbuf = NULL;\ndiff --git a/imap-send.c b/imap-send.c\nindex 84df2fa..4283a4a 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -224,7 +224,7 @@ socket_perror( const char *func, Socket_t *sock, int ret )\n static int\n socket_read( Socket_t *sock, char *buf, int len )\n {\n-\tint n = xread( sock->fd, buf, len );\n+\tssize_t n = xread( sock->fd, buf, len );\n \tif (n <= 0) {\n \t\tsocket_perror( \"read\", sock, n );\n \t\tclose( sock->fd );\ndiff --git a/index-pack.c b/index-pack.c\nindex b9da19f..58c4a9c 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -82,7 +82,7 @@ static void *fill(int min)\n \t\tdie(\"cannot fill %d bytes\", min);\n \tflush();\n \tdo {\n-\t\tint ret = xread(input_fd, input_buffer + input_len,\n+\t\tssize_t ret = xread(input_fd, input_buffer + input_len,\n \t\t\t\tsizeof(input_buffer) - input_len);\n \t\tif (ret <= 0) {\n \t\t\tif (!ret)\ndiff --git a/pkt-line.c b/pkt-line.c\nindex b4cb7e2..b605268 100644\n--- a/pkt-line.c\n+++ b/pkt-line.c\n@@ -65,10 +65,10 @@ void packet_write(int fd, const char *fmt, ...)\n \n static void safe_read(int fd, void *buffer, unsigned size)\n {\n-\tint n = 0;\n+\tsize_t n = 0;\n \n \twhile (n < size) {\n-\t\tint ret = xread(fd, (char *) buffer + n, size - n);\n+\t\tssize_t ret = xread(fd, (char *) buffer + n, size - n);\n \t\tif (ret < 0)\n \t\t\tdie(\"read error (%s)\", strerror(errno));\n \t\tif (!ret)\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 32244d7..be991ed 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2276,7 +2276,7 @@ int read_pipe(int fd, char** return_buf, unsigned long* return_size)\n {\n \tchar* buf = *return_buf;\n \tunsigned long size = *return_size;\n-\tint iret;\n+\tssize_t iret;\n \tunsigned long off = 0;\n \n \tdo {\ndiff --git a/ssh-upload.c b/ssh-upload.c\nindex 2f04572..498d41e 100644\n--- a/ssh-upload.c\n+++ b/ssh-upload.c\n@@ -86,7 +86,7 @@ static int serve_ref(int fd_in, int fd_out)\n \n static void service(int fd_in, int fd_out) {\n \tchar type;\n-\tint retval;\n+\tssize_t retval;\n \tdo {\n \t\tretval = xread(fd_in, &type, 1);\n \t\tif (retval < 1) {\n-- \n1.5.1.4\n"},{"id":"42229","messageId":"56b7f5510705150912x7ab3ac0clcd494d5f4367c314@mail.gmail.com","threadId":"8167","inReplyTo":"200705151449.22744.johan@herland.net","subject":"Re: [PATCH] Ensure return value from xread() is always stored into an ssize_t","fromName":"Dana How","fromEmail":"danahow@gmail.com","sentAt":"2007-05-15T16:12:21Z","receivedAt":"2007-05-15T16:12:21Z","isPatch":true,"sender":{"key":"danahow@gmail.com","avatar":null},"body":"Twice you change an int to a size_t (one s).\n[builtin-fetch-tool.c and pkt-line.c .]\nDid you want to do that?\n\nOn 5/15/07, Johan Herland <johan@herland.net> wrote:\n> This patch fixes all calls to xread() where the return value is not\n> stored into an ssize_t. The patch should not have any effect whatsoever,\n> other than putting better/more appropriate type names on variables.\n>\n> Signed-off-by: Johan Herland <johan@herland.net>\n> ---\n>\n> Feel free to ignore this patch as it may be argued that it needlessly\n> touches a lot of code, without having much (if any) positive effect\n> at all.\n>\n>  builtin-apply.c          |    4 ++--\n>  builtin-bundle.c         |    2 +-\n>  builtin-fetch--tool.c    |    4 ++--\n>  builtin-unpack-objects.c |    2 +-\n>  combine-diff.c           |    2 +-\n>  copy.c                   |    3 +--\n>  diff.c                   |    2 +-\n>  imap-send.c              |    2 +-\n>  index-pack.c             |    2 +-\n>  pkt-line.c               |    4 ++--\n>  sha1_file.c              |    2 +-\n>  ssh-upload.c             |    2 +-\n>  12 files changed, 15 insertions(+), 16 deletions(-)\n>\n> diff --git a/builtin-apply.c b/builtin-apply.c\n> index 8b8705a..0399743 100644\n> --- a/builtin-apply.c\n> +++ b/builtin-apply.c\n> @@ -185,7 +185,7 @@ static void *read_patch_file(int fd, unsigned long *sizep)\n>         void *buffer = xmalloc(alloc);\n>\n>         for (;;) {\n> -               int nr = alloc - size;\n> +               ssize_t nr = alloc - size;\n>                 if (nr < 1024) {\n>                         alloc += CHUNKSIZE;\n>                         buffer = xrealloc(buffer, alloc);\n> @@ -1468,7 +1468,7 @@ static int read_old_data(struct stat *st, const char *path, char **buf_p, unsign\n>                         return error(\"unable to open %s\", path);\n>                 got = 0;\n>                 for (;;) {\n> -                       int ret = xread(fd, buf + got, size - got);\n> +                       ssize_t ret = xread(fd, buf + got, size - got);\n>                         if (ret <= 0)\n>                                 break;\n>                         got += ret;\n> diff --git a/builtin-bundle.c b/builtin-bundle.c\n> index d1635a0..306ad29 100644\n> --- a/builtin-bundle.c\n> +++ b/builtin-bundle.c\n> @@ -48,7 +48,7 @@ static int read_string(int fd, char *buffer, int size)\n>  {\n>         int i;\n>         for (i = 0; i < size - 1; i++) {\n> -               int count = xread(fd, buffer + i, 1);\n> +               ssize_t count = xread(fd, buffer + i, 1);\n>                 if (count < 0)\n>                         return error(\"Read error: %s\", strerror(errno));\n>                 if (count == 0) {\n> diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c\n> index 2065466..12adb38 100644\n> --- a/builtin-fetch--tool.c\n> +++ b/builtin-fetch--tool.c\n> @@ -6,11 +6,11 @@\n>\n>  static char *get_stdin(void)\n>  {\n> -       int offset = 0;\n> +       size_t offset = 0;\n>         char *data = xmalloc(CHUNK_SIZE);\n>\n>         while (1) {\n> -               int cnt = xread(0, data + offset, CHUNK_SIZE);\n> +               ssize_t cnt = xread(0, data + offset, CHUNK_SIZE);\n>                 if (cnt < 0)\n>                         die(\"error reading standard input: %s\",\n>                             strerror(errno));\n> diff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c\n> index 2bbda67..a6ff62f 100644\n> --- a/builtin-unpack-objects.c\n> +++ b/builtin-unpack-objects.c\n> @@ -34,7 +34,7 @@ static void *fill(int min)\n>                 offset = 0;\n>         }\n>         do {\n> -               int ret = xread(0, buffer + len, sizeof(buffer) - len);\n> +               ssize_t ret = xread(0, buffer + len, sizeof(buffer) - len);\n>                 if (ret <= 0) {\n>                         if (!ret)\n>                                 die(\"early EOF\");\n> diff --git a/combine-diff.c b/combine-diff.c\n> index cff9c5d..ea3ca5f 100644\n> --- a/combine-diff.c\n> +++ b/combine-diff.c\n> @@ -714,7 +714,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n>                         result_size = len;\n>                         result = xmalloc(len + 1);\n>                         while (sz < len) {\n> -                               int done = xread(fd, result+sz, len-sz);\n> +                               ssize_t done = xread(fd, result+sz, len-sz);\n>                                 if (done == 0)\n>                                         break;\n>                                 if (done < 0)\n> diff --git a/copy.c b/copy.c\n> index 08a3d38..d340bb2 100644\n> --- a/copy.c\n> +++ b/copy.c\n> @@ -3,10 +3,9 @@\n>  int copy_fd(int ifd, int ofd)\n>  {\n>         while (1) {\n> -               int len;\n>                 char buffer[8192];\n>                 char *buf = buffer;\n> -               len = xread(ifd, buffer, sizeof(buffer));\n> +               ssize_t len = xread(ifd, buffer, sizeof(buffer));\n>                 if (!len)\n>                         break;\n>                 if (len < 0) {\n> diff --git a/diff.c b/diff.c\n> index 8354e71..33297aa 100644\n> --- a/diff.c\n> +++ b/diff.c\n> @@ -1411,7 +1411,7 @@ static int populate_from_stdin(struct diff_filespec *s)\n>  #define INCREMENT 1024\n>         char *buf;\n>         unsigned long size;\n> -       int got;\n> +       ssize_t got;\n>\n>         size = 0;\n>         buf = NULL;\n> diff --git a/imap-send.c b/imap-send.c\n> index 84df2fa..4283a4a 100644\n> --- a/imap-send.c\n> +++ b/imap-send.c\n> @@ -224,7 +224,7 @@ socket_perror( const char *func, Socket_t *sock, int ret )\n>  static int\n>  socket_read( Socket_t *sock, char *buf, int len )\n>  {\n> -       int n = xread( sock->fd, buf, len );\n> +       ssize_t n = xread( sock->fd, buf, len );\n>         if (n <= 0) {\n>                 socket_perror( \"read\", sock, n );\n>                 close( sock->fd );\n> diff --git a/index-pack.c b/index-pack.c\n> index b9da19f..58c4a9c 100644\n> --- a/index-pack.c\n> +++ b/index-pack.c\n> @@ -82,7 +82,7 @@ static void *fill(int min)\n>                 die(\"cannot fill %d bytes\", min);\n>         flush();\n>         do {\n> -               int ret = xread(input_fd, input_buffer + input_len,\n> +               ssize_t ret = xread(input_fd, input_buffer + input_len,\n>                                 sizeof(input_buffer) - input_len);\n>                 if (ret <= 0) {\n>                         if (!ret)\n> diff --git a/pkt-line.c b/pkt-line.c\n> index b4cb7e2..b605268 100644\n> --- a/pkt-line.c\n> +++ b/pkt-line.c\n> @@ -65,10 +65,10 @@ void packet_write(int fd, const char *fmt, ...)\n>\n>  static void safe_read(int fd, void *buffer, unsigned size)\n>  {\n> -       int n = 0;\n> +       size_t n = 0;\n>\n>         while (n < size) {\n> -               int ret = xread(fd, (char *) buffer + n, size - n);\n> +               ssize_t ret = xread(fd, (char *) buffer + n, size - n);\n>                 if (ret < 0)\n>                         die(\"read error (%s)\", strerror(errno));\n>                 if (!ret)\n> diff --git a/sha1_file.c b/sha1_file.c\n> index 32244d7..be991ed 100644\n> --- a/sha1_file.c\n> +++ b/sha1_file.c\n> @@ -2276,7 +2276,7 @@ int read_pipe(int fd, char** return_buf, unsigned long* return_size)\n>  {\n>         char* buf = *return_buf;\n>         unsigned long size = *return_size;\n> -       int iret;\n> +       ssize_t iret;\n>         unsigned long off = 0;\n>\n>         do {\n> diff --git a/ssh-upload.c b/ssh-upload.c\n> index 2f04572..498d41e 100644\n> --- a/ssh-upload.c\n> +++ b/ssh-upload.c\n> @@ -86,7 +86,7 @@ static int serve_ref(int fd_in, int fd_out)\n>\n>  static void service(int fd_in, int fd_out) {\n>         char type;\n> -       int retval;\n> +       ssize_t retval;\n>         do {\n>                 retval = xread(fd_in, &type, 1);\n>                 if (retval < 1) {\n> --\n> 1.5.1.4\n> -\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n\n-- \nDana L. How  danahow@gmail.com  +1 650 804 5991 cell\n"},{"id":"42231","messageId":"200705151821.58068.johan@herland.net","threadId":"8167","inReplyTo":"56b7f5510705150912x7ab3ac0clcd494d5f4367c314@mail.gmail.com","subject":"Re: [PATCH] Ensure return value from xread() is always stored into an ssize_t","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2007-05-15T16:21:57Z","receivedAt":"2007-05-15T16:21:57Z","isPatch":true,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"On Tuesday 15 May 2007, Dana How wrote:\n> Twice you change an int to a size_t (one s).\n> [builtin-fetch-tool.c and pkt-line.c .]\n> Did you want to do that?\n\nYes. AFAICS it was appropriate in the given context.\nI.e. in both cases the int was used as an positive offset/size, and\nalthough its value was altered by the ssize_t returned from xread(),\nthe ssize_t was always verified to be >= 0 before being added to the int.\n\n\nHave fun!\n\n...Johan\n\n> On 5/15/07, Johan Herland <johan@herland.net> wrote:\n> > This patch fixes all calls to xread() where the return value is not\n> > stored into an ssize_t. The patch should not have any effect whatsoever,\n> > other than putting better/more appropriate type names on variables.\n> >\n> > Signed-off-by: Johan Herland <johan@herland.net>\n> > ---\n> >\n> > Feel free to ignore this patch as it may be argued that it needlessly\n> > touches a lot of code, without having much (if any) positive effect\n> > at all.\n> >\n> >  builtin-apply.c          |    4 ++--\n> >  builtin-bundle.c         |    2 +-\n> >  builtin-fetch--tool.c    |    4 ++--\n> >  builtin-unpack-objects.c |    2 +-\n> >  combine-diff.c           |    2 +-\n> >  copy.c                   |    3 +--\n> >  diff.c                   |    2 +-\n> >  imap-send.c              |    2 +-\n> >  index-pack.c             |    2 +-\n> >  pkt-line.c               |    4 ++--\n> >  sha1_file.c              |    2 +-\n> >  ssh-upload.c             |    2 +-\n> >  12 files changed, 15 insertions(+), 16 deletions(-)\n> >\n> > diff --git a/builtin-apply.c b/builtin-apply.c\n> > index 8b8705a..0399743 100644\n> > --- a/builtin-apply.c\n> > +++ b/builtin-apply.c\n> > @@ -185,7 +185,7 @@ static void *read_patch_file(int fd, unsigned long *sizep)\n> >         void *buffer = xmalloc(alloc);\n> >\n> >         for (;;) {\n> > -               int nr = alloc - size;\n> > +               ssize_t nr = alloc - size;\n> >                 if (nr < 1024) {\n> >                         alloc += CHUNKSIZE;\n> >                         buffer = xrealloc(buffer, alloc);\n> > @@ -1468,7 +1468,7 @@ static int read_old_data(struct stat *st, const char *path, char **buf_p, unsign\n> >                         return error(\"unable to open %s\", path);\n> >                 got = 0;\n> >                 for (;;) {\n> > -                       int ret = xread(fd, buf + got, size - got);\n> > +                       ssize_t ret = xread(fd, buf + got, size - got);\n> >                         if (ret <= 0)\n> >                                 break;\n> >                         got += ret;\n> > diff --git a/builtin-bundle.c b/builtin-bundle.c\n> > index d1635a0..306ad29 100644\n> > --- a/builtin-bundle.c\n> > +++ b/builtin-bundle.c\n> > @@ -48,7 +48,7 @@ static int read_string(int fd, char *buffer, int size)\n> >  {\n> >         int i;\n> >         for (i = 0; i < size - 1; i++) {\n> > -               int count = xread(fd, buffer + i, 1);\n> > +               ssize_t count = xread(fd, buffer + i, 1);\n> >                 if (count < 0)\n> >                         return error(\"Read error: %s\", strerror(errno));\n> >                 if (count == 0) {\n> > diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c\n> > index 2065466..12adb38 100644\n> > --- a/builtin-fetch--tool.c\n> > +++ b/builtin-fetch--tool.c\n> > @@ -6,11 +6,11 @@\n> >\n> >  static char *get_stdin(void)\n> >  {\n> > -       int offset = 0;\n> > +       size_t offset = 0;\n> >         char *data = xmalloc(CHUNK_SIZE);\n> >\n> >         while (1) {\n> > -               int cnt = xread(0, data + offset, CHUNK_SIZE);\n> > +               ssize_t cnt = xread(0, data + offset, CHUNK_SIZE);\n> >                 if (cnt < 0)\n> >                         die(\"error reading standard input: %s\",\n> >                             strerror(errno));\n> > diff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c\n> > index 2bbda67..a6ff62f 100644\n> > --- a/builtin-unpack-objects.c\n> > +++ b/builtin-unpack-objects.c\n> > @@ -34,7 +34,7 @@ static void *fill(int min)\n> >                 offset = 0;\n> >         }\n> >         do {\n> > -               int ret = xread(0, buffer + len, sizeof(buffer) - len);\n> > +               ssize_t ret = xread(0, buffer + len, sizeof(buffer) - len);\n> >                 if (ret <= 0) {\n> >                         if (!ret)\n> >                                 die(\"early EOF\");\n> > diff --git a/combine-diff.c b/combine-diff.c\n> > index cff9c5d..ea3ca5f 100644\n> > --- a/combine-diff.c\n> > +++ b/combine-diff.c\n> > @@ -714,7 +714,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n> >                         result_size = len;\n> >                         result = xmalloc(len + 1);\n> >                         while (sz < len) {\n> > -                               int done = xread(fd, result+sz, len-sz);\n> > +                               ssize_t done = xread(fd, result+sz, len-sz);\n> >                                 if (done == 0)\n> >                                         break;\n> >                                 if (done < 0)\n> > diff --git a/copy.c b/copy.c\n> > index 08a3d38..d340bb2 100644\n> > --- a/copy.c\n> > +++ b/copy.c\n> > @@ -3,10 +3,9 @@\n> >  int copy_fd(int ifd, int ofd)\n> >  {\n> >         while (1) {\n> > -               int len;\n> >                 char buffer[8192];\n> >                 char *buf = buffer;\n> > -               len = xread(ifd, buffer, sizeof(buffer));\n> > +               ssize_t len = xread(ifd, buffer, sizeof(buffer));\n> >                 if (!len)\n> >                         break;\n> >                 if (len < 0) {\n> > diff --git a/diff.c b/diff.c\n> > index 8354e71..33297aa 100644\n> > --- a/diff.c\n> > +++ b/diff.c\n> > @@ -1411,7 +1411,7 @@ static int populate_from_stdin(struct diff_filespec *s)\n> >  #define INCREMENT 1024\n> >         char *buf;\n> >         unsigned long size;\n> > -       int got;\n> > +       ssize_t got;\n> >\n> >         size = 0;\n> >         buf = NULL;\n> > diff --git a/imap-send.c b/imap-send.c\n> > index 84df2fa..4283a4a 100644\n> > --- a/imap-send.c\n> > +++ b/imap-send.c\n> > @@ -224,7 +224,7 @@ socket_perror( const char *func, Socket_t *sock, int ret )\n> >  static int\n> >  socket_read( Socket_t *sock, char *buf, int len )\n> >  {\n> > -       int n = xread( sock->fd, buf, len );\n> > +       ssize_t n = xread( sock->fd, buf, len );\n> >         if (n <= 0) {\n> >                 socket_perror( \"read\", sock, n );\n> >                 close( sock->fd );\n> > diff --git a/index-pack.c b/index-pack.c\n> > index b9da19f..58c4a9c 100644\n> > --- a/index-pack.c\n> > +++ b/index-pack.c\n> > @@ -82,7 +82,7 @@ static void *fill(int min)\n> >                 die(\"cannot fill %d bytes\", min);\n> >         flush();\n> >         do {\n> > -               int ret = xread(input_fd, input_buffer + input_len,\n> > +               ssize_t ret = xread(input_fd, input_buffer + input_len,\n> >                                 sizeof(input_buffer) - input_len);\n> >                 if (ret <= 0) {\n> >                         if (!ret)\n> > diff --git a/pkt-line.c b/pkt-line.c\n> > index b4cb7e2..b605268 100644\n> > --- a/pkt-line.c\n> > +++ b/pkt-line.c\n> > @@ -65,10 +65,10 @@ void packet_write(int fd, const char *fmt, ...)\n> >\n> >  static void safe_read(int fd, void *buffer, unsigned size)\n> >  {\n> > -       int n = 0;\n> > +       size_t n = 0;\n> >\n> >         while (n < size) {\n> > -               int ret = xread(fd, (char *) buffer + n, size - n);\n> > +               ssize_t ret = xread(fd, (char *) buffer + n, size - n);\n> >                 if (ret < 0)\n> >                         die(\"read error (%s)\", strerror(errno));\n> >                 if (!ret)\n> > diff --git a/sha1_file.c b/sha1_file.c\n> > index 32244d7..be991ed 100644\n> > --- a/sha1_file.c\n> > +++ b/sha1_file.c\n> > @@ -2276,7 +2276,7 @@ int read_pipe(int fd, char** return_buf, unsigned long* return_size)\n> >  {\n> >         char* buf = *return_buf;\n> >         unsigned long size = *return_size;\n> > -       int iret;\n> > +       ssize_t iret;\n> >         unsigned long off = 0;\n> >\n> >         do {\n> > diff --git a/ssh-upload.c b/ssh-upload.c\n> > index 2f04572..498d41e 100644\n> > --- a/ssh-upload.c\n> > +++ b/ssh-upload.c\n> > @@ -86,7 +86,7 @@ static int serve_ref(int fd_in, int fd_out)\n> >\n> >  static void service(int fd_in, int fd_out) {\n> >         char type;\n> > -       int retval;\n> > +       ssize_t retval;\n> >         do {\n> >                 retval = xread(fd_in, &type, 1);\n> >                 if (retval < 1) {\n> > --\n> > 1.5.1.4\n> > -\n> > To unsubscribe from this list: send the line \"unsubscribe git\" in\n> > the body of a message to majordomo@vger.kernel.org\n> > More majordomo info at  http://vger.kernel.org/majordomo-info.html\n> \n\n\n\n-- \nJohan Herland, <johan@herland.net>\nwww.herland.net\n"},{"id":"42262","messageId":"20070515232435.GQ3141@spearce.org","threadId":"8167","inReplyTo":"200705151439.25871.johan@herland.net","subject":"Re: [PATCH] Fix signedness on return value from xread()","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-05-15T23:24:35Z","receivedAt":"2007-05-15T23:24:35Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Johan Herland <johan@herland.net> wrote:\n> The return value from xread() is ssize_t. \n> Paolo Teti <paolo.teti@gmail.com> pointed out that in this case, the \n> signed return value was assigned to an unsigned type (size_t). This patch \n> fixes that.\n\nThanks for fixing this.  Its rather embarrassing as:\n\n  commit 00be8dcc1aca3c1c1a94b39f0563d30d1fa89290\n  Author: Sami Farin <safari-kernel@safari.iki.fi>\n  Date:   Tue Apr 24 22:56:02 2007 +0300\n  \n      fast-import: size_t vs ssize_t\n      \n      size_t is unsigned, so (n < 0) is never true.\n      \n      Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n\nwas applied by me to fix this very bug and I also applied the\npatch that created the buggy copy in pack-write.c.\n\n-- \nShawn.\n"}]}