IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23553


Ignore:
Timestamp:
Mar 26, 2009, 9:20:04 AM (17 years ago)
Author:
eugene
Message:

a little more careful about overfilling the buffer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libohana/src/IOBufferOps.c

    r17483 r23553  
    2727int ReadtoIOBuffer (IOBuffer *buffer, int fd) {
    2828
    29   int Nread, Nfree;
     29  int Nread, Nfree, Nwant;
    3030
    3131  if (fd == 0) {
     
    3434  }
    3535
     36  // if we run out of space, double Nblock
    3637  Nfree = buffer[0].Nalloc - buffer[0].Nbuffer;
    3738  if (Nfree < buffer[0].Nblock) {
     
    4445  }
    4546
    46   Nread = read (fd, &buffer[0].buffer[buffer[0].Nbuffer], buffer[0].Nblock);
    47   if (DEBUG) fprintf (stderr, "read IO buffer: (%lx) %d from %d\n", (unsigned long) buffer, Nread, buffer[0].Nblock);
     47  // ensure we never read more than space available
     48  Nwant = MIN (Nfree, buffer[0].Nblock);
     49  Nread = read (fd, &buffer[0].buffer[buffer[0].Nbuffer], Nwant);
     50  if (DEBUG) fprintf (stderr, "read IO buffer: (%lx) %d from %d\n", (unsigned long) buffer, Nread, Nwant);
    4851
    4952  /* on success, increase the block size for the next read */
Note: See TracChangeset for help on using the changeset viewer.