From 337fa0e661abfa999e2b2dbd8161227933220ee3 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Thu, 24 May 2018 10:05:08 +0200
Subject: Fixed the trailing part address of multi-part portions.

---
 src/glibext/gbinportion.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/glibext/gbinportion.c b/src/glibext/gbinportion.c
index 27413f6..ab5fa6e 100644
--- a/src/glibext/gbinportion.c
+++ b/src/glibext/gbinportion.c
@@ -796,6 +796,7 @@ void g_binary_portion_include(GBinPortion *portion, GBinPortion *sub)
     phys_t overlapping;                     /* Taille de la zone commune   */
     bool continued;                         /* Suite d'une découpe ?       */
     GBinPortion *left_part;                 /* Partie intégrable           */
+    vmpa2t start;                           /* Départ de la seconde partie */
     GBinPortion *right_part;                /* Partie restante             */
 
     int g_binary_portion_is_included(const GBinPortion **a, const GBinPortion **b)
@@ -917,7 +918,17 @@ void g_binary_portion_include(GBinPortion *portion, GBinPortion *sub)
 
             /* Partie qui déborde... */
 
-            right_part = g_binary_portion_new(sub->code, &end, get_mrange_length(&sub->range) - overlapping);
+            /**
+             * Comme la portion incluante peut avoir une définition d'adresse
+             * virtuelle différente de celle de la portion incluse, on recalcule
+             * la position de départ de la seconde partie de la portion découpée
+             * à partir des données d'origine.
+             */
+
+            copy_vmpa(&start, get_mrange_addr(&sub->range));
+            advance_vmpa(&start, overlapping);
+
+            right_part = g_binary_portion_new(sub->code, &start, get_mrange_length(&sub->range) - overlapping);
 
             if (!continued)
                 g_binary_portion_mark_as_continued(right_part, true);
-- 
cgit v0.11.2-87-g4458