Commit 747e8ca3841d6e5752ad493b4a5d3855c00418e4

Baptiste 2024-08-01T15:14:17

wip

diff --git a/libkc3/buf.c b/libkc3/buf.c
index d5a5fdf..7184e11 100644
--- a/libkc3/buf.c
+++ b/libkc3/buf.c
@@ -526,6 +526,8 @@ sw buf_peek_str (s_buf *buf, const s_str *src)
     return 0;
   if ((r = buf_refill(buf, src->size)) < 0)
     return r;
+  if ((uw) r < src->size)
+    return -1;
   if (buf->rpos > buf->wpos) {
     assert(buf->rpos <= buf->wpos);
     return -1;
@@ -919,18 +921,14 @@ sw buf_refill (s_buf *buf, sw size)
 {
   sw r = buf->wpos - buf->rpos;
   assert(buf);
-  if (buf->read_only)
-    return r;
   if (size < 0) {
     err_puts("buf_refill: size < 0");
     assert(! "buf_refill: size < 0");
     return -1;
   }
-  if (! size) {
-    err_puts("buf_refill: size = 0");
-    assert(! "buf_refill: size = 0");
-    return 0;
-  }
+  if (buf->read_only ||
+      ! size)
+    return r;
   if (buf->rpos + size > buf->wpos) {
     if ((r = buf_refill_compact(buf)) < 0) {
       err_puts("buf_refill: buf_refill_compact");
diff --git a/libkc3/buf_parse.c b/libkc3/buf_parse.c
index 187a2c8..b1af68d 100644
--- a/libkc3/buf_parse.c
+++ b/libkc3/buf_parse.c
@@ -339,7 +339,7 @@ sw buf_parse_array_dimensions_rec (s_buf *buf, s_array *dest,
   address[dimension] = 0;
   while (1) {
     if (dimension == dest->dimension - 1) {
-      if ((r = buf_parse_tag(buf, &tag)) < 0) {
+      if ((r = buf_parse_tag(buf, &tag)) <= 0) {
         err_puts("buf_parse_array_dimensions_rec: buf_parse_tag");
         goto clean;
       }
@@ -433,6 +433,7 @@ sw buf_parse_block (s_buf *buf, s_block *block)
   if ((r = buf_parse_block_inner(buf, short_form, block)) < 0) {
     err_puts("buf_parse_block: buf_parse_block_inner < 0");
     err_inspect_buf(buf);
+    err_write_1("\n");
     assert(! "buf_parse_block: buf_parse_block_inner < 0");
     goto restore;
   }
@@ -533,7 +534,7 @@ sw buf_parse_block_inner (s_buf *buf, bool short_form, s_block *block)
       goto restore;
     }
     if (! r) {
-      if ((r = buf_read_1(buf, ";")) <= 0) {
+      if ((r = buf_read_1(buf, ";")) < 0) {
         err_write_1("buf_parse_block_inner: line ");
         err_inspect_sw_decimal(&buf->line);
         err_puts(": missing separator: ");
@@ -542,6 +543,8 @@ sw buf_parse_block_inner (s_buf *buf, bool short_form, s_block *block)
         assert(! "buf_parse_block_inner: missing separator");
         goto restore;
       }
+      if (! r)
+        goto restore;
     }
     result += r;
     if ((r = buf_parse_comments(buf)) < 0) {