From: mquinson Date: Thu, 26 Mar 2009 13:37:04 +0000 (+0000) Subject: Deal with negative indices the same way than too big indices X-Git-Tag: v3.3~39 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b0e970d2b1c9049f80db76445c4f24e8a266c3cb Deal with negative indices the same way than too big indices git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6172 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/xbt/dynar.c b/src/xbt/dynar.c index 7572c34e7a..90adeb5aa7 100644 --- a/src/xbt/dynar.c +++ b/src/xbt/dynar.c @@ -41,7 +41,7 @@ static XBT_INLINE void _sanity_check_idx(int idx) { } static XBT_INLINE void _check_inbound_idx(xbt_dynar_t dynar, int idx) { - if (idx>=dynar->used) { + if (idx<0 || idx>=dynar->used) { _dynar_unlock(dynar); THROW2(bound_error,idx, "dynar is not that long. You asked %d, but it's only %lu long", @@ -147,7 +147,6 @@ _xbt_dynar_remove_at(xbt_dynar_t const dynar, unsigned long offset; _sanity_check_dynar(dynar); - _sanity_check_idx(idx); _check_inbound_idx(dynar, idx); if (object) { @@ -340,7 +339,6 @@ xbt_dynar_get_cpy(const xbt_dynar_t dynar, void * const dst) { _dynar_lock(dynar); _sanity_check_dynar(dynar); - _sanity_check_idx(idx); _check_inbound_idx(dynar, idx); _xbt_dynar_get_elm(dst, dynar, idx); @@ -362,7 +360,6 @@ xbt_dynar_get_ptr(const xbt_dynar_t dynar, const unsigned long idx) { void *res; _dynar_lock(dynar); _sanity_check_dynar(dynar); - _sanity_check_idx(idx); _check_inbound_idx(dynar, idx); res = _xbt_dynar_elm(dynar, idx);