From fa231d636f07240f8549f313557be5a4767f6faa Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Tue, 29 Jul 2014 12:50:06 -0300
Subject: [PATCH 1/2] Don't copy_dive double deleted when removing an event.

The copy_dive assumed that the event being removed was from
current_dive, wich was untill a very recent past. now it
can't assume that anymore, so instead of setting ev =
assumed_dive->event->next, we do a ev = current_dive->event->next.

Fixes #663

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 dive.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/dive.c b/dive.c
index acab8ff..dacc433 100644
--- a/dive.c
+++ b/dive.c
@@ -70,8 +70,13 @@ void remove_event(struct event* event)
 	while (ep && !same_event(*ep, event))
 		ep = &(*ep)->next;
 	if (ep) {
-		*ep = event->next;
-		free(event);
+		/* we can't link directly with event->next
+		 * because 'event' can be a copy from another
+		 * dive ( for instance the displayed_dive
+		 * that we use on the interface to show things. */
+		struct event *temp = (*ep)->next;
+		free(*ep);
+		*ep = temp;
 	}
 }
 
-- 
2.0.3

From 17d6dfeabac8873f8cfe923271dffd7fa89d252c Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Tue, 29 Jul 2014 13:06:30 -0300
Subject: [PATCH 2/2] C++ Correctness and code cleanup.

Use const-reference where we can gain a bit of speed from that
and clear an else { if {}} by using else if.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/groupedlineedit.cpp |  2 +-
 qt-ui/mainwindow.cpp      | 10 ++++------
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/qt-ui/groupedlineedit.cpp b/qt-ui/groupedlineedit.cpp
index 28758e0..4867089 100644
--- a/qt-ui/groupedlineedit.cpp
+++ b/qt-ui/groupedlineedit.cpp
@@ -106,7 +106,7 @@ void GroupedLineEdit::removeAllColors()
 QStringList GroupedLineEdit::getBlockStringList()
 {
 	QStringList retList;
-	foreach (Private::Block block, d->blocks)
+	foreach (const Private::Block &block, d->blocks)
 		retList.append(block.text);
 	return retList;
 }
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index c847660..cb6dc79 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -1029,18 +1029,16 @@ void MainWindow::removeRecentFile(QStringList failedFiles)
 		}
 	}
 
-	foreach (QString file, failedFiles)
+	foreach (const QString &file, failedFiles)
 		files.removeAll(file);
 
 	for (int c = 1; c <= 4; c++) {
 		QString key = QString("File_%1").arg(c);
 
-		if (files.count() >= c) {
+		if (files.count() >= c)
 			s.setValue(key, files.at(c - 1));
-		} else {
-			if (s.contains(key))
-				s.remove(key);
-		}
+		else if (s.contains(key))
+			s.remove(key);
 	}
 
 	s.endGroup();
-- 
2.0.3

_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to