From 1790465d3dc002beafb91cc52d8aa6319dc67b35 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Wed, 3 Nov 2021 13:20:59 +0100 Subject: Removed carrN_elem(). Added assert in carrN_at(). --- include/stc/carr2.h | 9 ++++----- include/stc/carr3.h | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/stc/carr2.h b/include/stc/carr2.h index a1dfc3ce..b961c47e 100644 --- a/include/stc/carr2.h +++ b/include/stc/carr2.h @@ -76,11 +76,10 @@ STC_INLINE size_t _cx_memb(_size)(_cx_self arr) STC_INLINE _cx_value *_cx_memb(_data)(_cx_self* self) { return *self->data; } -STC_INLINE _cx_value *_cx_memb(_elem)(_cx_self* self, size_t x, size_t y) - { return *self->data + self->ydim*x + y; } - -STC_INLINE const _cx_value *_cx_memb(_at)(const _cx_self* self, size_t x, size_t y) - { return *self->data + self->ydim*x + y; } +STC_INLINE const _cx_value *_cx_memb(_at)(const _cx_self* self, size_t x, size_t y) { + assert(x < self->xdim && y < self->ydim); + return *self->data + self->ydim*x + y; +} STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { if (self->data == other.data) return; diff --git a/include/stc/carr3.h b/include/stc/carr3.h index 4d4fc84e..3f230204 100644 --- a/include/stc/carr3.h +++ b/include/stc/carr3.h @@ -78,11 +78,10 @@ STC_INLINE size_t _cx_memb(_size)(_cx_self arr) STC_INLINE _cx_value* _cx_memb(_data)(_cx_self* self) { return **self->data; } -STC_INLINE _cx_value* _cx_memb(_elem)(_cx_self* self, size_t x, size_t y, size_t z) - { return **self->data + self->zdim*(self->ydim*x + y) + z; } - -STC_INLINE const _cx_value* _cx_memb(_at)(const _cx_self* self, size_t x, size_t y, size_t z) - { return **self->data + self->zdim*(self->ydim*x + y) + z; } +STC_INLINE const _cx_value* _cx_memb(_at)(const _cx_self* self, size_t x, size_t y, size_t z) { + assert(x < self->xdim && y < self->ydim && z < self->zdim); + return **self->data + self->zdim*(self->ydim*x + y) + z; +} STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { if (self->data == other.data) return; -- cgit v1.2.3