Commit 1ff44728b523df11aad01bf31dc19c624de7b199

Thomas de Grivel 2024-12-08T09:30:05

wip buf

diff --git a/libkc3/buf.c b/libkc3/buf.c
index da4eba9..ee65738 100644
--- a/libkc3/buf.c
+++ b/libkc3/buf.c
@@ -1140,6 +1140,8 @@ sw buf_write (s_buf *buf, const void *data, uw len)
 sw buf_write_1 (s_buf *buf, const char *p)
 {
   s_str str;
+  assert(buf);
+  assert(p);
   str_init_1(&str, NULL, p);
   return buf_write_str(buf, &str);
 }
diff --git a/libkc3/buf.h b/libkc3/buf.h
index 5dbd502..7f15ff4 100644
--- a/libkc3/buf.h
+++ b/libkc3/buf.h
@@ -23,7 +23,7 @@
 #include <stdlib.h>
 #include "types.h"
 
-#define BUF_SIZE 10240
+#define BUF_SIZE 1024024
 
 #define PROTO_BUF_PEEK(type)                                           \
   sw buf_peek_ ## type (s_buf *buf, type *dest)
diff --git a/test/buf_test.c b/test/buf_test.c
index 53043f9..2486e65 100644
--- a/test/buf_test.c
+++ b/test/buf_test.c
@@ -350,10 +350,10 @@ TEST_CASE_END(buf_peek_character_utf8)
 
 TEST_CASE(buf_peek_s8)
 {
-  char a[4] = "ABCD";
+  char a[5] = "ABCD";
   s_buf buf;
   s8 byte;
-  buf_init(&buf, false, sizeof(a), a);
+  buf_init_const(&buf, sizeof(a), a);
   TEST_EQ(buf.rpos, 0);
   TEST_EQ(buf_peek_s8(&buf, &byte), -1);
   TEST_EQ(buf.rpos, 0);
@@ -362,12 +362,17 @@ TEST_CASE(buf_peek_s8)
   TEST_EQ(buf.rpos, 0);
   TEST_EQ(byte, 'A');
   TEST_EQ(buf.wpos, 1);
-  buf.wpos = 4;
+  buf.rpos = 1;
+  TEST_EQ(buf_peek_s8(&buf, &byte), -1);
+  TEST_EQ(buf.rpos, 1);
+  TEST_EQ(byte, 'A');
+  TEST_EQ(buf.wpos, 1);
+  buf.wpos = 3;
   buf.rpos = 1;
   TEST_EQ(buf_peek_s8(&buf, &byte), 1);
   TEST_EQ(buf.rpos, 1);
   TEST_EQ(byte, 'B');
-  TEST_EQ(buf.wpos, 4);
+  TEST_EQ(buf.wpos, 3);
   buf_clean(&buf);
 }
 TEST_CASE_END(buf_peek_s8)
@@ -513,7 +518,7 @@ TEST_CASE(buf_read_s8)
   char a[8] = "ABCDEFG";
   s_buf buf;
   s8 byte;
-  buf_init(&buf, false, sizeof(a), a);
+  buf_init_const(&buf, sizeof(a), a);
   TEST_EQ(buf_read_s8(&buf, &byte), -1);
   TEST_EQ(buf_read_s8(&buf, &byte), -1);
   buf.wpos = 1;
@@ -522,9 +527,11 @@ TEST_CASE(buf_read_s8)
   TEST_EQ(buf.rpos, 1);
   TEST_EQ(buf.wpos, 1);
   TEST_EQ(buf_read_s8(&buf, &byte), -1);
+  TEST_EQ(byte, 'A');
   TEST_EQ(buf.rpos, 1);
   TEST_EQ(buf.wpos, 1);
   TEST_EQ(buf_read_s8(&buf, &byte), -1);
+  TEST_EQ(byte, 'A');
   TEST_EQ(buf.rpos, 1);
   TEST_EQ(buf.wpos, 1);
   buf.wpos = 5;