From c6d610b3ae7344e3f209515558daf0b4a8667824 Mon Sep 17 00:00:00 2001 From: Arnaud Legrand Date: Fri, 27 Apr 2012 00:27:38 +0200 Subject: [PATCH] Let's not assume that an unsigned long int always behave as a char *... When it comes to such pointer arithmetic, char * is the way to go. Plus plug a dumb memleak. Sorry about the previous commit that did not work with full compilation flags. --- src/xbt/dynar.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/xbt/dynar.c b/src/xbt/dynar.c index 7e7512bee2..513fc13602 100644 --- a/src/xbt/dynar.c +++ b/src/xbt/dynar.c @@ -737,12 +737,12 @@ XBT_PUBLIC(void) xbt_dynar_three_way_partition(xbt_dynar_t const dynar, { _dynar_lock(dynar); unsigned long size = xbt_dynar_length(dynar); - void *data = dynar->data; + char *data = (char *) dynar->data; unsigned long int i; unsigned long int p = -1; unsigned long int q = size; - unsigned long elmsize = dynar->elmsize; - void *tmp = xbt_malloc(elmsize); + const unsigned long elmsize = dynar->elmsize; + char *tmp = xbt_malloc(elmsize); #define swap(a,b) do { \ memcpy(tmp, a , elmsize); \ @@ -751,20 +751,21 @@ XBT_PUBLIC(void) xbt_dynar_three_way_partition(xbt_dynar_t const dynar, } while(0) for (i = 0; i < q;) { - unsigned long int datai = ((unsigned long int) data) + i*elmsize; - int colori = color((void *) datai); + char *datai = data + i*elmsize; + int colori = color(datai); if(colori==0) { - unsigned long int datap = ((unsigned long int) data) + (++p)*elmsize; - swap((void *) datai, (void *) datap); + char *datap = data + (++p)*elmsize; + swap(datai, datap); ++i; } else if (colori==2) { - unsigned long int dataq = ((unsigned long int) data) + (--q)*elmsize; - swap((void *) datai, (void *) dataq); + char *dataq = data + (--q)*elmsize; + swap(datai, dataq); } else { ++i; } } + xbt_free(tmp); _dynar_unlock(dynar); } -- 2.20.1