Commit bf1109d9cfc564da231ead8ee507e3f28e497f05

Baptiste 2024-08-07T13:28:18

fix buf and buf_getc

diff --git a/libkc3/buf.c b/libkc3/buf.c
index cb5d31b..3078663 100644
--- a/libkc3/buf.c
+++ b/libkc3/buf.c
@@ -995,6 +995,12 @@ sw buf_refill_compact (s_buf *buf)
     if (min_rpos == buf->wpos) {
       buf->rpos = 0;
       buf->wpos = 0;
+      save = buf->save;
+      while (save) {
+        save->rpos -= min_rpos;
+        save->wpos -= min_rpos;
+        save = save->next;
+      }
     }
     else {
       size = buf->wpos - min_rpos;
@@ -1011,9 +1017,8 @@ sw buf_refill_compact (s_buf *buf)
       }
       buf->wpos = size;
     }
-    return 1;
   }
-  return 0;
+  return 1;
 }
 
 s_str * buf_slice_to_str (const s_buf *buf, uw start, uw end,
diff --git a/libkc3/buf_getc.c b/libkc3/buf_getc.c
index 37d46a1..28b98d1 100644
--- a/libkc3/buf_getc.c
+++ b/libkc3/buf_getc.c
@@ -61,7 +61,8 @@ sw buf_getc_refill (s_buf *buf)
          c != '\n' &&
          (c = getc(fp)) != EOF &&
          c <= 255) {
-    buf_write_u8(buf, c);
+    if (buf_write_u8(buf, c) < 0)
+      return -1;
     result++;
   }
   return result;