wip
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
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) {