summaryrefslogtreecommitdiffstats
path: root/libdimension/dimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-02-10 11:42:56 -0500
committerTavian Barnes <tavianator@gmail.com>2010-02-10 11:42:56 -0500
commita4eb36a5df16fadfb0d86167acaaef7bd60daf7c (patch)
tree621c50a541d8621f3e6db40cb7fc6c10629ecb5f /libdimension/dimension
parent46404ea1b6ad634a0a6b815dc0b2d43234433149 (diff)
downloaddimension-a4eb36a5df16fadfb0d86167acaaef7bd60daf7c.tar.xz
Use dmnsn_assert for array range checks.
Diffstat (limited to 'libdimension/dimension')
-rw-r--r--libdimension/dimension/array.h17
1 files changed, 3 insertions, 14 deletions
diff --git a/libdimension/dimension/array.h b/libdimension/dimension/array.h
index c1e28cd..6ac5957 100644
--- a/libdimension/dimension/array.h
+++ b/libdimension/dimension/array.h
@@ -97,10 +97,7 @@ dmnsn_array_resize(dmnsn_array *array, size_t length)
DMNSN_INLINE void
dmnsn_array_get(const dmnsn_array *array, size_t i, void *obj)
{
- if (i >= dmnsn_array_size(array)) {
- /* Range check failed */
- dmnsn_error(DMNSN_SEVERITY_HIGH, "Array index out of bounds.");
- }
+ dmnsn_assert(i < dmnsn_array_size(array), "Array index out of bounds.");
memcpy(obj, (char *)array->ptr + array->obj_size*i, array->obj_size);
}
@@ -139,11 +136,7 @@ DMNSN_INLINE void
dmnsn_array_pop(dmnsn_array *array, void *obj)
{
size_t size = dmnsn_array_size(array);
- if (size <= 0) {
- /* Range check failed */
- dmnsn_error(DMNSN_SEVERITY_HIGH, "Array is empty.");
- }
-
+ dmnsn_assert(size > 0, "Array is empty.");
dmnsn_array_get(array, size - 1, obj); /* Copy the object */
dmnsn_array_resize(array, size - 1); /* Shrink the array */
}
@@ -170,11 +163,7 @@ DMNSN_INLINE void
dmnsn_array_remove(dmnsn_array *array, size_t i)
{
size_t size = dmnsn_array_size(array);
- if (i >= size) {
- /* Range check failed */
- dmnsn_error(DMNSN_SEVERITY_HIGH, "Array index out of bounds.");
- }
-
+ dmnsn_assert(i < size, "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),