commit 8fcaf9187ea756e2430bb6350a886ab1637dd09f
parent 944ed7ee99b37bcc47fc8df972c1a374fc46b414
Author: vaplv <vaplv@free.fr>
Date: Thu, 25 May 2017 13:07:34 +0200
Fix the big_buffer resize function
The big buffer file was truncated without taking into account neither
the size of the big buffer header nor the size of the big buffer data.
Diffstat:
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/big_buffer.h b/src/big_buffer.h
@@ -30,7 +30,7 @@ enum bigbuf_flag {
BIGBUF_LOAD_STREAM = BIT(1)
};
-extern LOCAL_SYM res_T
+RSYS_API res_T
truncate__
(FILE* file,
const size_t sz);
@@ -372,7 +372,8 @@ BIGBUF_FUNC__(resize)(struct BIGBUF__* bigbuf, const size_t size)
bigbuf->size = size;
bigbuf->end = bigbuf->head + (long)(bigbuf->size*sizeof(BIGBUF_DATA));
- res = truncate__(bigbuf->file, bigbuf->size);
+ res = truncate__
+ (bigbuf->file, bigbuf->size*sizeof(BIGBUF_DATA) + sizeof(size_t)/*header*/);
if(res != RES_OK) goto error;
exit:
@@ -382,6 +383,30 @@ error:
}
static INLINE res_T
+BIGBUF_FUNC__(set)
+ (struct BIGBUF__* bigbuf, const size_t at, const BIGBUF_DATA* data)
+{
+ res_T res = RES_OK;
+ ASSERT(bigbuf && data);
+
+ if(at >= bigbuf->size) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ res = BIGBUF_FUNC__(fetch__)(bigbuf, at);
+ if(res != RES_OK) goto error;
+
+ ASSERT(at >= bigbuf->buf_index);
+ bigbuf->buf.data[at - bigbuf->buf_index] = *data;
+
+exit:
+ return res;
+error:
+ goto exit;
+}
+
+static INLINE res_T
BIGBUF_FUNC__(at)(struct BIGBUF__* bigbuf, const size_t at, BIGBUF_DATA* data)
{
res_T res = RES_OK;