From cd4fe3e06985f2d0b107abd301f704156a0489c2 Mon Sep 17 00:00:00 2001
From: Ludovic Pouzenc <ludovic@pouzenc.fr>
Date: Mon, 15 Aug 2011 17:20:13 +0000
Subject: Ajout d'une gestion du zoom très primitive du dump dans curses. Il y
 avait un méchant bug dans le calcul des intervales pour le sb/se.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

git-svn-id: file:///var/svn/2011-ddhardrescue/trunk@22 d3078510-dda0-49f1-841c-895ef4b7ec81
---
 src/slices.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

(limited to 'src/slices.c')

diff --git a/src/slices.c b/src/slices.c
index e84facf..36f7bb1 100644
--- a/src/slices.c
+++ b/src/slices.c
@@ -214,19 +214,21 @@ char *slicesDump(slices_t *slices, address_t *blockSize, unsigned int charCount,
 
 	//For each slice
 	while (curr != NULL) {
-		// If is (partially) contained in the [begin,end] interval
-		if ( (curr->begin >= begin && curr->begin <=end) || ( curr->end >= end && curr->end <= end ) ) {
-
+		// If "curr" slice is (partially) contained/visible in the [begin,end] display interval
+		if ( !(curr->end < begin) && !(curr->begin > end) ) {
 			// Draw the slice on the right number of characters
-			sb=MAX(0, (curr->begin - begin) / *blockSize);
+			// Mathematically correct, but crashes because address_t is UNSIGNED
+			// sb=MAX(0, (curr->begin - begin) / *blockSize);
+			sb=(curr->begin < begin)?0:(curr->begin - begin) / *blockSize;
 			se=MIN((curr->end - begin) / *blockSize, charCount-1);
 
-			// Debug assertion
+			/* Debug "assertion"
 			if (sb >= charCount || se >= charCount) {
 				printf("BUG : sb==%lli, se=%lli, charCount==%i\n", sb, se, charCount);
+				printf("BUG : MAX(0, (%lli - %lli) / %lli)", curr->begin, begin, *blockSize);
 				pthread_mutex_unlock(&(slices->writeOrConsistentReadMutex));
 				exit(42);
-			}
+			}*/
 			
 			// Choose from the current slice status the right char to draw
 			switch (curr->status) {
-- 
cgit v1.2.3