summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-05-16 17:05:36 +0200
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-05-16 17:29:22 +0200
commitca914eb17bfdb2e56a39951a96a9fb54e1a5f607 (patch)
treec552c75886dd88eb9ebdc3e31ea92df17df1f7fd
parentcd14d5db7abdb12b5e46a6c055daf5304bb43b74 (diff)
downloadouroboros-ca914eb17bfdb2e56a39951a96a9fb54e1a5f607.tar.gz
ouroboros-ca914eb17bfdb2e56a39951a96a9fb54e1a5f607.zip
lib: Add missing modulo calculation
Adds a missing modulo calculation that would result in index -1 being returned instead of zero when the ringbuffer skipped back to the beginning.
-rw-r--r--include/ouroboros/shm_ap_rbuff.h4
-rw-r--r--include/ouroboros/shm_du_map.h20
-rw-r--r--src/ipcpd/shim-udp/main.c3
-rw-r--r--src/lib/dev.c2
-rw-r--r--src/lib/shm_du_map.c20
5 files changed, 24 insertions, 25 deletions
diff --git a/include/ouroboros/shm_ap_rbuff.h b/include/ouroboros/shm_ap_rbuff.h
index 0ee3e81e..956a9540 100644
--- a/include/ouroboros/shm_ap_rbuff.h
+++ b/include/ouroboros/shm_ap_rbuff.h
@@ -37,8 +37,8 @@
struct shm_ap_rbuff;
struct rb_entry {
- size_t index;
- int port_id;
+ ssize_t index;
+ int port_id;
};
struct shm_ap_rbuff * shm_ap_rbuff_create();
diff --git a/include/ouroboros/shm_du_map.h b/include/ouroboros/shm_du_map.h
index f575aa42..35d85b11 100644
--- a/include/ouroboros/shm_du_map.h
+++ b/include/ouroboros/shm_du_map.h
@@ -47,18 +47,18 @@ void shm_du_map_close(struct shm_du_map * dum);
void shm_du_map_destroy(struct shm_du_map * dum);
/* returns the index of the buffer in the DU map */
-int shm_create_du_buff(struct shm_du_map * dum,
- size_t size,
- size_t headspace,
- uint8_t * data,
- size_t len);
+ssize_t shm_create_du_buff(struct shm_du_map * dum,
+ size_t size,
+ size_t headspace,
+ uint8_t * data,
+ size_t len);
/* FIXME: revise these */
-int shm_du_map_read_sdu(uint8_t ** dst,
- struct shm_du_map * dum,
- size_t idx);
-int shm_release_du_buff(struct shm_du_map * dum, size_t idx);
-
+int shm_du_map_read_sdu(uint8_t ** dst,
+ struct shm_du_map * dum,
+ ssize_t idx);
+int shm_release_du_buff(struct shm_du_map * dum,
+ ssize_t idx);
/* FIXME: use shm_du_map * and index */
uint8_t * shm_du_buff_head_alloc(struct shm_du_buff * sdb,
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c
index e3f7fcdd..0802583c 100644
--- a/src/ipcpd/shim-udp/main.c
+++ b/src/ipcpd/shim-udp/main.c
@@ -204,8 +204,7 @@ static int port_id_to_fd(int port_id)
static ssize_t ipcp_udp_flow_write(int fd, void * buf, size_t count)
{
- /* the AP chooses the amount of headspace and tailspace */
- size_t index;
+ ssize_t index;
struct rb_entry e;
rw_lock_rdlock(&_ipcp->state_lock);
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 9b29b992..c365a17b 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -531,7 +531,7 @@ int flow_cntl(int fd, int cmd, int oflags)
ssize_t flow_write(int fd, void * buf, size_t count)
{
- size_t index;
+ ssize_t index;
struct rb_entry e;
if (buf == NULL)
diff --git a/src/lib/shm_du_map.c b/src/lib/shm_du_map.c
index 7099b265..a7ec5ac9 100644
--- a/src/lib/shm_du_map.c
+++ b/src/lib/shm_du_map.c
@@ -227,11 +227,11 @@ void shm_du_map_destroy(struct shm_du_map * dum)
free(dum);
}
-int shm_create_du_buff(struct shm_du_map * dum,
- size_t size,
- size_t headspace,
- uint8_t * data,
- size_t len)
+ssize_t shm_create_du_buff(struct shm_du_map * dum,
+ size_t size,
+ size_t headspace,
+ uint8_t * data,
+ size_t len)
{
struct shm_du_buff * sdb;
long blocks = 0;
@@ -239,7 +239,7 @@ int shm_create_du_buff(struct shm_du_map * dum,
int sz2 = headspace + len + sizeof *sdb;
uint8_t * write_pos;
size_t copy_len;
- size_t index;
+ ssize_t index;
if (dum == NULL || data == NULL) {
LOG_DBGF("Bogus input, bugging out.");
@@ -294,7 +294,7 @@ int shm_create_du_buff(struct shm_du_map * dum,
--blocks;
}
- index = *dum->ptr_head - 1;
+ index = (*dum->ptr_head - 1) & (SHM_BLOCKS_IN_MAP - 1);
pthread_mutex_unlock(dum->shm_mutex);
@@ -304,9 +304,9 @@ int shm_create_du_buff(struct shm_du_map * dum,
/* FIXME: this cannot handle packets stretching beyond the ringbuffer border */
int shm_du_map_read_sdu(uint8_t ** dst,
struct shm_du_map * dum,
- size_t idx)
+ ssize_t idx)
{
- size_t len = 0;
+ size_t len = 0;
if (idx > SHM_BLOCKS_IN_MAP)
return -1;
@@ -328,7 +328,7 @@ int shm_du_map_read_sdu(uint8_t ** dst,
return len;
}
-int shm_release_du_buff(struct shm_du_map * dum, size_t idx)
+int shm_release_du_buff(struct shm_du_map * dum, ssize_t idx)
{
long sz;
long blocks = 0;