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

Re: [PATCH] remove unnecessary test and dead diagnostic

From
Jeff King <peff@peff.net>
Date
May 26, 2011, 14:11 UTC
Message-ID
<20110526141130.GB18520@sigill.intra.peff.net>
In-Reply-To
<87tych5zrh.fsf@rho.meyering.net>
On Thu, May 26, 2011 at 03:59:14PM +0200, Jim Meyering wrote:
> * sha1_file.c (index_stream): Don't check for size_t < 0.
> read_in_full does not return an indication of failure.
Are you sure about that?
  $ sed -n '/read_in_full/,/^}/p' wrapper.c
  ssize_t read_in_full(int fd, void *buf, size_t count)
  {
          char *p = buf;
          ssize_t total = 0;
          while (count > 0) {
                  ssize_t loaded = xread(fd, p, count);
                  if (loaded <= 0)
                          return total ? total : loaded;
                  count -= loaded;
                  p += loaded;
                  total += loaded;
          }
          return total;
  }

It looks like if we get -1 on the _first_ read, we will then return -1. Subsequent errors are then ignored, and we return the (possibly truncated) result.

Which, to be honest, seems kind of insane to me. I'd think:
  while (count > 0) {
          ssize_t loaded = xread(fd, p, count);
          if (loaded < 0)
                  return loaded;
          if (loaded == 0)
                  return total;
          ...
  }
would be much more sensible semantics.
-Peff
Previous: Jim MeyeringNext: Jim Meyering
Message 2 of 10 in “remove unnecessary test and dead diagnostic”
  1. remove unnecessary test and dead diagnosticJim Meyering, May 26, 2011
  2. Jeff KingMay 26, 2011
  3. Jim MeyeringMay 26, 2011
  4. Jeff KingMay 26, 2011
  5. Jim MeyeringMay 26, 2011
  6. read_in_full: always report errorsJeff King, May 26, 2011
  7. Junio C HamanoMay 26, 2011
  8. Jeff KingMay 26, 2011
  9. Junio C HamanoMay 26, 2011
  10. Jeff KingMay 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.