diff options
author | Dimitri Staessens <[email protected]> | 2016-03-15 15:44:57 +0100 |
---|---|---|
committer | Dimitri Staessens <[email protected]> | 2016-03-15 15:44:57 +0100 |
commit | ceaea65296a9cb6e2235b0dd429ab3d590b634d3 (patch) | |
tree | de41d0f550f86da1a671fcbbcb65fa15439c78b5 /src/lib/du_buff.c | |
parent | 74dc5818ac8586fcc36915874592c9f4fbb4e6f6 (diff) | |
download | ouroboros-ceaea65296a9cb6e2235b0dd429ab3d590b634d3.tar.gz ouroboros-ceaea65296a9cb6e2235b0dd429ab3d590b634d3.zip |
lib: Updated du_buff not limit allowable PCI size
PCI can now occupy at most one block
Diffstat (limited to 'src/lib/du_buff.c')
-rw-r--r-- | src/lib/du_buff.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/lib/du_buff.c b/src/lib/du_buff.c index cf523847..7e0f502e 100644 --- a/src/lib/du_buff.c +++ b/src/lib/du_buff.c @@ -24,16 +24,15 @@ #include <malloc.h> #include <string.h> #include <errno.h> -#include "ouroboros/du_buff.h" +#include <ouroboros/du_buff.h> +#include <ouroboros/list.h> #define OUROBOROS_PREFIX "du_buff" -#ifndef DU_BUFF_BLOCKSIZE -#define DU_BUFF_BLOCKSIZE (1 << 16) -#endif - #include "ouroboros/logs.h" +#define DU_BLOCK_DATA_SIZE (DU_BUFF_BLOCK_SIZE - sizeof (struct buffer)) + struct buffer { uint8_t * data; size_t size; @@ -79,9 +78,13 @@ struct buffer * buffer_create (size_t size, size_t headspace, size_t len) { struct buffer * head = NULL; size_t remaining = size; - const size_t page_size = DU_BUFF_BLOCKSIZE; size_t ts = size - (headspace + len); - bool head_block = true; + + if (headspace > DU_BLOCK_DATA_SIZE || ts > DU_BLOCK_DATA_SIZE) + { + LOG_WARN("Illegal du_buff. Cannot fit PCI in DU_BUFF_BLOCK."); + return NULL; + } head = malloc(sizeof *head); if (head == NULL) @@ -97,17 +100,15 @@ struct buffer * buffer_create (size_t size, size_t headspace, size_t len) size_t sz; - if (size > DU_BUFF_BLOCKSIZE && head_block) { - sz = headspace; - head_block = false; - } else if (size > DU_BUFF_BLOCKSIZE - && remaining - ts <= DU_BUFF_BLOCKSIZE + if (size > DU_BLOCK_DATA_SIZE + && remaining - ts <= DU_BLOCK_DATA_SIZE && remaining != ts) { sz = remaining - ts; - } else if (size > DU_BUFF_BLOCKSIZE && remaining == ts) { + } else if (size > DU_BLOCK_DATA_SIZE && remaining == ts) { sz = ts; } else { - sz = remaining < page_size ? remaining : page_size; + sz = remaining < DU_BLOCK_DATA_SIZE ? + remaining : DU_BLOCK_DATA_SIZE; } buf = malloc(sizeof *buf); @@ -290,7 +291,7 @@ int du_buff_init(du_buff_t * dub, } if (start + len > dub->size) { - LOG_DBGF("Buffer too small for data %lu.", start); + LOG_DBGF("Buffer too small for data."); return -EINVAL; } |