[PATCH] Bugfix crash in trip statistics for non trip dives

Anton Lundin glance at acc.umu.se
Sun Nov 24 02:27:37 UTC 2013


This fixes a crash when you have non-trip dives in your logbook.

Signed-off-by: Anton Lundin <glance at acc.umu.se>
---
 statistics.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/statistics.c b/statistics.c
index 13c5003..51b8d60 100644
--- a/statistics.c
+++ b/statistics.c
@@ -155,21 +155,23 @@ void process_all_dives(struct dive *dive, struct dive **prev_dive)
 		stats_yearly[year_iter].selection_size++;
 		stats_yearly[year_iter].period = current_year;
 
-		if (trip_ptr != dp->divetrip) {
-			trip_ptr = dp->divetrip;
-			trip_iter++;
-		}
+		if (dp->divetrip != NULL) {
+			if (trip_ptr != dp->divetrip) {
+				trip_ptr = dp->divetrip;
+				trip_iter++;
+			}
 
-		/* stats_by_trip[0] is all the dives combined */
-		stats_by_trip[0].selection_size++;
-		process_dive(dp, &(stats_by_trip[0]));
-		stats_by_trip[0].is_trip = TRUE;
-		stats_by_trip[0].location = strdup("All (by trip stats)");
+			/* stats_by_trip[0] is all the dives combined */
+			stats_by_trip[0].selection_size++;
+			process_dive(dp, &(stats_by_trip[0]));
+			stats_by_trip[0].is_trip = TRUE;
+			stats_by_trip[0].location = strdup("All (by trip stats)");
 
-		process_dive(dp, &(stats_by_trip[trip_iter]));
-		stats_by_trip[trip_iter].selection_size++;
-		stats_by_trip[trip_iter].is_trip = TRUE;
-		stats_by_trip[trip_iter].location = dp->divetrip->location;
+			process_dive(dp, &(stats_by_trip[trip_iter]));
+			stats_by_trip[trip_iter].selection_size++;
+			stats_by_trip[trip_iter].is_trip = TRUE;
+			stats_by_trip[trip_iter].location = dp->divetrip->location;
+		}
 
 		/* monthly statistics */
 		if (current_month == 0) {
-- 
1.8.3.2



More information about the subsurface mailing list