diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-02-10 23:55:18 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-02-10 23:55:18 -0500 |
commit | 141b98f33748b7bb628f8453a4c06a0f6a52c0f4 (patch) | |
tree | 195c01395292968aba14322444e2c98c5b4fc4f3 /libdimension/dimension | |
parent | a4eb36a5df16fadfb0d86167acaaef7bd60daf7c (diff) | |
download | dimension-141b98f33748b7bb628f8453a4c06a0f6a52c0f4.tar.xz |
Revert "Use dmnsn_assert for array range checks."
This reverts commit a4eb36a5df16fadfb0d86167acaaef7bd60daf7c. Having
dmnsn_assert() in inline functions may change their definition depending on the
value of NDEBUG, which violates C++ inline rules.
Diffstat (limited to 'libdimension/dimension')
-rw-r--r-- | libdimension/dimension/array.h | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/libdimension/dimension/array.h b/libdimension/dimension/array.h index 6ac5957..c1e28cd 100644 --- a/libdimension/dimension/array.h +++ b/libdimension/dimension/array.h @@ -97,7 +97,10 @@ dmnsn_array_resize(dmnsn_array *array, size_t length) DMNSN_INLINE void dmnsn_array_get(const dmnsn_array *array, size_t i, void *obj) { - dmnsn_assert(i < dmnsn_array_size(array), "Array index out of bounds."); + if (i >= dmnsn_array_size(array)) { + /* Range check failed */ + dmnsn_error(DMNSN_SEVERITY_HIGH, "Array index out of bounds."); + } memcpy(obj, (char *)array->ptr + array->obj_size*i, array->obj_size); } @@ -136,7 +139,11 @@ DMNSN_INLINE void dmnsn_array_pop(dmnsn_array *array, void *obj) { size_t size = dmnsn_array_size(array); - dmnsn_assert(size > 0, "Array is empty."); + if (size <= 0) { + /* Range check failed */ + dmnsn_error(DMNSN_SEVERITY_HIGH, "Array is empty."); + } + dmnsn_array_get(array, size - 1, obj); /* Copy the object */ dmnsn_array_resize(array, size - 1); /* Shrink the array */ } @@ -163,7 +170,11 @@ DMNSN_INLINE void dmnsn_array_remove(dmnsn_array *array, size_t i) { size_t size = dmnsn_array_size(array); - dmnsn_assert(i < size, "Array index out of bounds."); + if (i >= size) { + /* Range check failed */ + dmnsn_error(DMNSN_SEVERITY_HIGH, "Array index out of bounds."); + } + /* Move the array elements after `i' 1 to the left */ memmove((char *)array->ptr + array->obj_size*i, (char *)array->ptr + array->obj_size*(i + 1), |