summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Dritschler <timo.dritschler@kit.edu>2015-02-09 18:06:05 +0100
committerTimo Dritschler <timo.dritschler@kit.edu>2015-02-09 19:30:51 +0100
commit7440dfe96a8047fb39c34fa6bc0a0e5339fd1b52 (patch)
treeb03a2b5f73f5bfb6add52802f293f206033cae36
parent315bef63d3774eb0ad64820508e967dd09dee303 (diff)
downloadkiro-7440dfe96a8047fb39c34fa6bc0a0e5339fd1b52.tar.gz
kiro-7440dfe96a8047fb39c34fa6bc0a0e5339fd1b52.tar.bz2
kiro-7440dfe96a8047fb39c34fa6bc0a0e5339fd1b52.tar.xz
kiro-7440dfe96a8047fb39c34fa6bc0a0e5339fd1b52.zip
Fixed a bug with kiro_trb_get_element returning the wrong address
Changed kiro_trb_get_element interface to allow negative element indices
-rw-r--r--src/kiro-trb.c18
-rw-r--r--src/kiro-trb.h2
2 files changed, 13 insertions, 7 deletions
diff --git a/src/kiro-trb.c b/src/kiro-trb.c
index 6a4a080..c3ed968 100644
--- a/src/kiro-trb.c
+++ b/src/kiro-trb.c
@@ -187,7 +187,7 @@ kiro_trb_get_raw_buffer (KiroTrb *self)
void *
-kiro_trb_get_element (KiroTrb *self, uint64_t element)
+kiro_trb_get_element (KiroTrb *self, glong element_in)
{
g_return_val_if_fail (self != NULL, NULL);
KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
@@ -195,12 +195,18 @@ kiro_trb_get_element (KiroTrb *self, uint64_t element)
if (priv->initialized != 1)
return NULL;
- uint64_t relative = 0;
+ gulong offset = element_in;
+ if (0 <= element_in) {
+ offset %= priv->max_elements;
+ offset = priv->max_elements - offset;
+ }
+ else {
+ offset *= -1;
+ offset %= priv->max_elements;
+ }
- if (priv->iteration == 0)
- relative = element * priv->element_size;
- else
- relative = ((priv->current - priv->frame_top) + (priv->element_size * element)) % (priv->buff_size - sizeof (struct KiroTrbInfo));
+ gulong relative = (priv->current - priv->frame_top) + (offset * priv->element_size);
+ relative %= (priv->buff_size - sizeof(struct KiroTrbInfo));
return priv->frame_top + relative;
}
diff --git a/src/kiro-trb.h b/src/kiro-trb.h
index 806ad5e..6620191 100644
--- a/src/kiro-trb.h
+++ b/src/kiro-trb.h
@@ -199,7 +199,7 @@ void* kiro_trb_get_raw_buffer (KiroTrb *trb);
* See also:
* kiro_trb_get_element_size, kiro_trb_get_raw_buffer
*/
-void* kiro_trb_get_element (KiroTrb *trb, uint64_t index);
+void* kiro_trb_get_element (KiroTrb *trb, glong index);
/**