Commit a2ff0facd4b2b40c7e357db3b8933bb9ff534b22

Thomas de Grivel 2024-09-09T20:07:03

fix buf_fd_open_r_refill

diff --git a/libkc3/buf_fd.c b/libkc3/buf_fd.c
index 5378ed2..2b14cde 100644
--- a/libkc3/buf_fd.c
+++ b/libkc3/buf_fd.c
@@ -53,7 +53,7 @@ sw buf_fd_open_r_refill (s_buf *buf)
 {
   int avail;
   s32 fd;
-  uw r;
+  sw r;
   uw size;
   assert(buf);
   assert(buf->user_ptr);
@@ -85,6 +85,8 @@ sw buf_fd_open_r_refill (s_buf *buf)
   if ((uw) avail > size)
     avail = size;
   r = read(fd, buf->ptr.pchar + buf->wpos, avail);
+  if (r < 0)
+    return r;
   if (buf->wpos + r > buf->size) {
     err_puts("buf_fd_open_r_refill: buffer overflow");
     assert(! "buf_fd_open_r_refill: buffer overflow");