diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2017-01-13 23:48:47 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2017-01-13 23:56:28 (GMT) |
commit | a156dc15cccb54d662b0085c8e4f27767dd5542f (patch) | |
tree | 46fdadb99945b315f823a1359415ab5acbc5fad9 /src/glibext | |
parent | d5b82c659081827182b2afbef468327b381fb850 (diff) |
Fortified the tree of binary portions.
Diffstat (limited to 'src/glibext')
-rw-r--r-- | src/glibext/gbinportion.c | 61 | ||||
-rw-r--r-- | src/glibext/gbinportion.h | 3 |
2 files changed, 48 insertions, 16 deletions
diff --git a/src/glibext/gbinportion.c b/src/glibext/gbinportion.c index 4849caa..e5dedd6 100644 --- a/src/glibext/gbinportion.c +++ b/src/glibext/gbinportion.c @@ -310,6 +310,30 @@ int g_binary_portion_compare(const GBinPortion **a, const GBinPortion **b) /****************************************************************************** * * +* Paramètres : a = premières informations à consulter. * +* b = secondes informations à consulter. * +* * +* Description : Détermine si une portion est comprise dans une autre. * +* * +* Retour : Bilan : -1 (a < b), 0 (b € a) ou 1 (a > b). * +* * +* Remarques : - * +* * +******************************************************************************/ + +int g_binary_portion_is_included(const GBinPortion **a, const GBinPortion **b) +{ + int result; /* Bilan à retourner */ + + result = mrange_includes_mrange(&(*b)->range, &(*a)->range); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : portion = description de partie à mettre à jour. * * desc = nom à donner à la partie. * * * @@ -654,12 +678,11 @@ void g_binary_portion_include(GBinPortion *portion, GBinPortion *sub) { bool found; /* Zone d'accueil trouvée ? */ size_t best; /* Meilleur point d'insertion */ - const mrange_t *prange; /* Emplacement de portion #1 */ - const mrange_t *srange; /* Emplacement de portion #2 */ - GBinPortion tmp; /* Sauvegarde temporaire */ + size_t i; /* Boucle de parcours */ + GBinPortion *tmp; /* Sauvegarde temporaire */ - found = bsearch_index(sub, portion->subs, portion->count, sizeof(GBinPortion *), - (__compar_fn_t)g_binary_portion_compare, &best); + found = bsearch_index(&sub, portion->subs, portion->count, sizeof(GBinPortion *), + (__compar_fn_t)g_binary_portion_is_included, &best); if (!found) portion->subs = qinsert(portion->subs, &portion->count, sizeof(GBinPortion *), @@ -678,24 +701,30 @@ void g_binary_portion_include(GBinPortion *portion, GBinPortion *sub) * de zones mémoire. */ - prange = g_binary_portion_get_range(portion->subs[best]); - srange = g_binary_portion_get_range(sub); + if (mrange_includes_mrange(&sub->range, &portion->subs[best]->range) == 0) + { + tmp = portion->subs[best]; - if (mrange_contains_mrange(prange, srange)) - g_binary_portion_include(portion->subs[best], sub); + for (i = portion->count; i > 0; i--) + { + tmp = portion->subs[i - 1]; - else - { - assert(mrange_contains_mrange(srange, prange)); + if (mrange_includes_mrange(&sub->range, &tmp->range) == 0) + { + portion->subs = _qdelete(portion->subs, &portion->count, sizeof(GBinPortion *), i - 1); + g_binary_portion_include(sub, tmp); + } - memcpy(&tmp, portion->subs[best], sizeof(GBinPortion)); - memcpy(portion->subs[best], sub, sizeof(GBinPortion)); - memcpy(sub, &tmp, sizeof(GBinPortion)); + } - g_binary_portion_include(portion->subs[best], sub); + portion->subs = qinsert(portion->subs, &portion->count, sizeof(GBinPortion *), + (__compar_fn_t)g_binary_portion_compare, &sub); } + else + g_binary_portion_include(portion->subs[best], sub); + } } diff --git a/src/glibext/gbinportion.h b/src/glibext/gbinportion.h index f05713e..a1ec105 100644 --- a/src/glibext/gbinportion.h +++ b/src/glibext/gbinportion.h @@ -84,6 +84,9 @@ GBinPortion *g_binary_portion_new(const char *, const vmpa2t *, phys_t); /* Etablit la comparaison ascendante entre deux portions. */ int g_binary_portion_compare(const GBinPortion **, const GBinPortion **); +/* Détermine si une portion est comprise dans une autre. */ +int g_binary_portion_is_included(const GBinPortion **, const GBinPortion **); + /* Attribue une description humaine à une partie de code. */ void g_binary_portion_set_desc(GBinPortion *, const char *); |