From bab3cdd90e8ef97a4aa71593edf67c4bb8fa4c09 Mon Sep 17 00:00:00 2001 From: DTB Date: Sun, 7 Jul 2024 18:14:48 -0600 Subject: [PATCH] dj(1): Io_write: don't add to bufuse --- src/dj.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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;