diff options
author | Timo Dritschler <timo.dritschler@kit.edu> | 2015-02-09 18:06:05 +0100 |
---|---|---|
committer | Timo Dritschler <timo.dritschler@kit.edu> | 2015-02-09 19:30:51 +0100 |
commit | 7440dfe96a8047fb39c34fa6bc0a0e5339fd1b52 (patch) | |
tree | b03a2b5f73f5bfb6add52802f293f206033cae36 /src/kiro-trb.c | |
parent | 315bef63d3774eb0ad64820508e967dd09dee303 (diff) | |
download | kiro-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
Diffstat (limited to 'src/kiro-trb.c')
-rw-r--r-- | src/kiro-trb.c | 18 |
1 files changed, 12 insertions, 6 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; } |