From 7872695ec9fe584f51b529d102bb55ac11b9c3c7 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 13 Aug 2018 16:48:50 +0200 Subject: [PATCH] extract out shared isl_multi_*_check_range Signed-off-by: Sven Verdoolaege --- isl_multi_move_dims_templ.c | 6 ++---- isl_multi_splice_templ.c | 7 +++---- isl_multi_templ.c | 31 ++++++++++++------------------- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/isl_multi_move_dims_templ.c b/isl_multi_move_dims_templ.c index 1b6e6ca9..9c880857 100644 --- a/isl_multi_move_dims_templ.c +++ b/isl_multi_move_dims_templ.c @@ -38,10 +38,8 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),move_dims)(__isl_take MULTI(BASE) *multi, isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid, "cannot move divs", return FN(MULTI(BASE),free)(multi)); - if (src_pos + n > isl_space_dim(multi->space, src_type)) - isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid, - "range out of bounds", - return FN(MULTI(BASE),free)(multi)); + if (FN(MULTI(BASE),check_range)(multi, src_type, src_pos, n) < 0) + return FN(MULTI(BASE),free)(multi); if (dst_type == src_type) isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_unsupported, "moving dims within the same type not supported", diff --git a/isl_multi_splice_templ.c b/isl_multi_splice_templ.c index c315b853..dbeb0856 100644 --- a/isl_multi_splice_templ.c +++ b/isl_multi_splice_templ.c @@ -45,11 +45,10 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),splice)( if (!multi1 || !multi2) goto error; - n_in1 = FN(MULTI(BASE),dim)(multi1, isl_dim_in); - if (in_pos > n_in1) - isl_die(FN(MULTI(BASE),get_ctx)(multi1), isl_error_invalid, - "index out of bounds", goto error); + if (FN(MULTI(BASE),check_range)(multi1, isl_dim_in, in_pos, 0) < 0) + goto error; + n_in1 = FN(MULTI(BASE),dim)(multi1, isl_dim_in); n_in2 = FN(MULTI(BASE),dim)(multi2, isl_dim_in); multi1 = FN(MULTI(BASE),insert_dims)(multi1, isl_dim_in, in_pos, n_in2); diff --git a/isl_multi_templ.c b/isl_multi_templ.c index a5c9939d..c0887f95 100644 --- a/isl_multi_templ.c +++ b/isl_multi_templ.c @@ -228,17 +228,19 @@ __isl_give isl_id *FN(MULTI(BASE),get_tuple_id)(__isl_keep MULTI(BASE) *multi, return multi ? isl_space_get_tuple_id(multi->space, type) : NULL; } +#undef TYPE +#define TYPE MULTI(BASE) +static +#include "check_type_range_templ.c" + __isl_give EL *FN(FN(MULTI(BASE),get),BASE)(__isl_keep MULTI(BASE) *multi, int pos) { isl_ctx *ctx; - if (!multi) + if (FN(MULTI(BASE),check_range)(multi, isl_dim_out, pos, 1) < 0) return NULL; ctx = FN(MULTI(BASE),get_ctx)(multi); - if (pos < 0 || pos >= multi->n) - isl_die(ctx, isl_error_invalid, - "index out of bounds", return NULL); return FN(EL,copy)(multi->u.p[pos]); } @@ -252,9 +254,8 @@ static __isl_give MULTI(BASE) *FN(MULTI(BASE),restore)( if (!multi || !el) goto error; - if (pos < 0 || pos >= multi->n) - isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid, - "index out of bounds", goto error); + if (FN(MULTI(BASE),check_range)(multi, isl_dim_out, pos, 1) < 0) + goto error; FN(EL,free)(multi->u.p[pos]); multi->u.p[pos] = el; @@ -598,17 +599,10 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),drop_dims)( enum isl_dim_type type, unsigned first, unsigned n) { int i; - unsigned dim; multi = FN(MULTI(BASE),cow)(multi); - if (!multi) - return NULL; - - dim = FN(MULTI(BASE),dim)(multi, type); - if (first + n > dim || first + n < first) - isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid, - "index out of bounds", - return FN(MULTI(BASE),free)(multi)); + if (FN(MULTI(BASE),check_range)(multi, type, first, n) < 0) + return FN(MULTI(BASE),free)(multi); multi->space = isl_space_drop_dims(multi->space, type, first, n); if (!multi->space) @@ -873,10 +867,9 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),range_splice)( if (!multi1 || !multi2) goto error; + if (FN(MULTI(BASE),check_range)(multi1, isl_dim_out, pos, 0) < 0) + goto error; dim = FN(MULTI(BASE),dim)(multi1, isl_dim_out); - if (pos > dim) - isl_die(FN(MULTI(BASE),get_ctx)(multi1), isl_error_invalid, - "index out of bounds", goto error); res = FN(MULTI(BASE),copy)(multi1); res = FN(MULTI(BASE),drop_dims)(res, isl_dim_out, pos, dim - pos); -- 2.11.4.GIT