From 4baed63971ea82804c68d65209645b1bc043be94 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 27 Jan 2017 12:47:31 +0100 Subject: [PATCH] isl_*_list_insert: fix inserting elements at position 0 Due to an integer promotion to unsigned integers, an internal loop would not terminate resulting in invalid memory accesses. Signed-off-by: Sven Verdoolaege --- isl_list_templ.c | 4 ++-- isl_test.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/isl_list_templ.c b/isl_list_templ.c index aa900b95..84292279 100644 --- a/isl_list_templ.c +++ b/isl_list_templ.c @@ -192,8 +192,8 @@ __isl_give LIST(EL) *FN(LIST(EL),insert)(__isl_take LIST(EL) *list, "index out of bounds", goto error); if (list->ref == 1 && list->size > list->n) { - for (i = list->n - 1; i >= pos; --i) - list->p[i + 1] = list->p[i]; + for (i = list->n; i > pos; --i) + list->p[i] = list->p[i - 1]; list->n++; list->p[pos] = el; return list; diff --git a/isl_test.c b/isl_test.c index 11977a95..0f659087 100644 --- a/isl_test.c +++ b/isl_test.c @@ -5440,8 +5440,8 @@ static int test_list(isl_ctx *ctx) d = isl_id_alloc(ctx, "d", NULL); list = isl_id_list_alloc(ctx, 4); - list = isl_id_list_add(list, a); list = isl_id_list_add(list, b); + list = isl_id_list_insert(list, 0, a); list = isl_id_list_add(list, c); list = isl_id_list_add(list, d); list = isl_id_list_drop(list, 1, 1); -- 2.11.4.GIT