From 0f29c57b4aa4066cdfd6ed1fbce87855aa07fd13 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sat, 4 Jul 2020 22:48:52 +0200 Subject: [PATCH] Use correct type for variables, and avoid loosing precision. --- src/xbt/automaton/automaton.c | 4 ++-- src/xbt/mmalloc/mmalloc.c | 2 +- src/xbt/mmalloc/mrealloc.c | 4 ++-- teshsuite/simdag/availability/availability.c | 2 +- teshsuite/simdag/basic-parsing-test/basic-parsing-test.c | 6 +++--- teshsuite/smpi/bug-17132/bug-17132.c | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/xbt/automaton/automaton.c b/src/xbt/automaton/automaton.c index 1d6be9f2a4..5fc60df54e 100644 --- a/src/xbt/automaton/automaton.c +++ b/src/xbt/automaton/automaton.c @@ -329,9 +329,9 @@ int xbt_automaton_exp_label_compare(const_xbt_automaton_exp_label_t l1, const_xb int xbt_automaton_propositional_symbols_compare_value(const_xbt_dynar_t s1, const_xbt_dynar_t s2) { - unsigned int nb_elem = xbt_dynar_length(s1); + unsigned long nb_elem = xbt_dynar_length(s1); - for (unsigned int cursor = 0; cursor < nb_elem; cursor++) { + for (unsigned long cursor = 0; cursor < nb_elem; cursor++) { const int* iptr1 = xbt_dynar_get_ptr(s1, cursor); const int* iptr2 = xbt_dynar_get_ptr(s2, cursor); if(*iptr1 != *iptr2) diff --git a/src/xbt/mmalloc/mmalloc.c b/src/xbt/mmalloc/mmalloc.c index 4eb0133213..d3c26bbd26 100644 --- a/src/xbt/mmalloc/mmalloc.c +++ b/src/xbt/mmalloc/mmalloc.c @@ -54,7 +54,7 @@ static void initialize_heapinfo_heapinfo(const s_xbt_mheap_t* mdp) { // Update heapinfo about the heapinfo pages (!): xbt_assert((uintptr_t) mdp->heapinfo % BLOCKSIZE == 0); - int block = BLOCK(mdp->heapinfo); + size_t block = BLOCK(mdp->heapinfo); size_t nblocks = mdp->heapsize * sizeof(malloc_info) / BLOCKSIZE; // Mark them as free: for (size_t j=0; j!=nblocks; ++j) { diff --git a/src/xbt/mmalloc/mrealloc.c b/src/xbt/mmalloc/mrealloc.c index 186cc66ba0..4ce18deaf3 100644 --- a/src/xbt/mmalloc/mrealloc.c +++ b/src/xbt/mmalloc/mrealloc.c @@ -79,7 +79,7 @@ void *mrealloc(xbt_mheap_t mdp, void *ptr, size_t size) /* Full blocks -> Full blocks; see if we can hold it in place. */ blocks = BLOCKIFY(size); if (blocks < mdp->heapinfo[block].busy_block.size) { - int it; + size_t it; /* The new size is smaller; return excess memory to the free list. */ for (it= block+blocks; it< mdp->heapinfo[block].busy_block.size ; it++){ mdp->heapinfo[it].type = MMALLOC_TYPE_UNFRAGMENTED; // FIXME that should be useless, type should already be 0 here @@ -134,7 +134,7 @@ void *mrealloc(xbt_mheap_t mdp, void *ptr, size_t size) /* The new size is the same kind of fragment. */ result = ptr; - int frag_nb = RESIDUAL(result, BLOCKSIZE) >> type; + uintptr_t frag_nb = RESIDUAL(result, BLOCKSIZE) >> type; mdp->heapinfo[block].busy_frag.frag_size[frag_nb] = requested_size; mdp->heapinfo[block].busy_frag.ignore[frag_nb] = 0; diff --git a/teshsuite/simdag/availability/availability.c b/teshsuite/simdag/availability/availability.c index 6c307656cf..16fe88fe46 100644 --- a/teshsuite/simdag/availability/availability.c +++ b/teshsuite/simdag/availability/availability.c @@ -21,7 +21,7 @@ static void scheduleDAX(const_xbt_dynar_t dax) SD_task_t task; sg_host_t *hosts = sg_host_list(); - int totalHosts = sg_host_count(); + size_t totalHosts = sg_host_count(); qsort((void *) hosts, totalHosts, sizeof(sg_host_t), name_compare_hosts); xbt_dynar_foreach(dax, cursor, task) { diff --git a/teshsuite/simdag/basic-parsing-test/basic-parsing-test.c b/teshsuite/simdag/basic-parsing-test/basic-parsing-test.c index 4a075a86af..5464341c26 100644 --- a/teshsuite/simdag/basic-parsing-test/basic-parsing-test.c +++ b/teshsuite/simdag/basic-parsing-test/basic-parsing-test.c @@ -37,11 +37,11 @@ int main(int argc, char **argv) xbt_dynar_free_container(&route); } if (!strcmp(argv[2], "FULL_LINK")) { - int list_size = sg_host_count(); - for (int i = 0; i < list_size; i++) { + size_t list_size = sg_host_count(); + for (size_t i = 0; i < list_size; i++) { const_sg_host_t h1 = hosts[i]; const char *name1 = sg_host_get_name(h1); - for (int j = 0; j < list_size; j++) { + for (size_t j = 0; j < list_size; j++) { const_sg_host_t h2 = hosts[j]; const char *name2 = sg_host_get_name(h2); fprintf(stderr, "Route between %s and %s\n", name1, name2); diff --git a/teshsuite/smpi/bug-17132/bug-17132.c b/teshsuite/smpi/bug-17132/bug-17132.c index 16c35f2cc3..bb9cd25b00 100644 --- a/teshsuite/smpi/bug-17132/bug-17132.c +++ b/teshsuite/smpi/bug-17132/bug-17132.c @@ -11,8 +11,8 @@ int main(int argc, char ** argv) { - size_t M = 8*1024; - size_t N = 32*1024; + const int M = 8 * 1024; + const int N = 32 * 1024; MPI_Init(&argc, &argv); -- 2.20.1