From d800cb1c80ec68eb1ad85134fd9c0727023f572a Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Fri, 21 Oct 2016 23:33:03 +0200
Subject: Fixed bugs as realloc() may change base addresses and does not
 initialize new memory.

---
 ChangeLog                   | 6 ++++++
 src/glibext/gwidthtracker.c | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index ee1fa84..336a34b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 16-10-21  Cyrille Bagard <nocbos@gmail.com>
 
+	* src/glibext/gwidthtracker.c:
+	Compute again portion addresses after reallocations as their base address
+	may have changed. Do not use uninitialized value as cache status.
+
+16-10-21  Cyrille Bagard <nocbos@gmail.com>
+
 	* src/common/shuffle.c:
 	Avoid to copy overlapping memory areas.
 
diff --git a/src/glibext/gwidthtracker.c b/src/glibext/gwidthtracker.c
index 10d01ab..94e7f36 100644
--- a/src/glibext/gwidthtracker.c
+++ b/src/glibext/gwidthtracker.c
@@ -518,6 +518,8 @@ void g_width_tracker_update_added(GWidthTracker *tracker, size_t index, size_t c
             tracker->portions = (common_metrics *)realloc(tracker->portions,
                                                           tracker->count * sizeof(common_metrics));
 
+            portion = &tracker->portions[current];
+
             dest = current + 2;
             src = current + 1;
 
@@ -535,6 +537,8 @@ void g_width_tracker_update_added(GWidthTracker *tracker, size_t index, size_t c
                 tracker->portions[current + 1].first = portion->first + 1;
                 tracker->portions[current + 1].last = portion->last;
 
+                tracker->portions[current + 1].cached = false;
+
                 portion->first = i;
                 portion->last = i;
 
@@ -546,6 +550,8 @@ void g_width_tracker_update_added(GWidthTracker *tracker, size_t index, size_t c
                 tracker->portions[current + 1].first = i;
                 tracker->portions[current + 1].last = portion->last;
 
+                tracker->portions[current + 1].cached = false;
+
                 portion->last = i - 1;
 
             }
-- 
cgit v0.11.2-87-g4458