diff --git a/src/dj.c b/src/dj.c index 2be2ecb..4dc4842 100644 --- a/src/dj.c +++ b/src/dj.c @@ -93,7 +93,9 @@ Io_write(struct Io *io){ assert(io->bufuse > 0); assert(io->bufuse <= io->bs); - if((t = write(io->fd, io->buf, io->bufuse)) > 0) + if((t = write(io->fd, io->buf, io->bufuse)) < 0) + t = 0; + else if(t > 0) memmove(io->buf, &(io->buf)[t], (io->bufuse -= t)); io->bytes += t; @@ -268,6 +270,7 @@ int main(int argc, char *argv[]){ t = io[0].bufuse; if(Io_read(&io[0])->bufuse == t && !noerror) Io_read(&io[0]); /* second chance */ + assert(io[0].bufuse >= t); if(io[0].bufuse == t) /* that's all she wrote */ break; @@ -321,6 +324,7 @@ int main(int argc, char *argv[]){ t = io[1].bufuse; if(Io_write(&io[1])->bufuse == t && !noerror) Io_write(&io[1]); /* second chance */ + assert(io[1].bufuse <= t); if(io[1].bufuse == t){ /* no more love */ count = 1; break;