summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2016-01-18 11:44:05 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-01-18 11:45:25 -0800
commit38c60e02c7705044f8b7eb9ea177139a63239446 (patch)
treef5e4909ffa08bace86862ef52869262db3c82973
parent040d3cd413a303b43e72607c6d6ba05932a9a5b3 (diff)
downloadsubsurface-38c60e02c7705044f8b7eb9ea177139a63239446.tar.gz
Fix crash with empty (or very short) dive list
In commit 37c10c8fd6 ("Add dive type to statistics window") not enough space is reserved for the newly introduced array if the dive list as fewer than 4 entries. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--subsurface-core/statistics.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/subsurface-core/statistics.c b/subsurface-core/statistics.c
index ab0aaac3f..373a6a0d0 100644
--- a/subsurface-core/statistics.c
+++ b/subsurface-core/statistics.c
@@ -101,7 +101,7 @@ void process_all_dives(struct dive *dive, struct dive **prev_dive)
int prev_month = 0, prev_year = 0;
int trip_iter = 0;
dive_trip_t *trip_ptr = 0;
- unsigned int size;
+ unsigned int size, tsize;
*prev_dive = NULL;
memset(&stats, 0, sizeof(stats));
@@ -121,16 +121,17 @@ void process_all_dives(struct dive *dive, struct dive **prev_dive)
free(stats_by_type);
size = sizeof(stats_t) * (dive_table.nr + 1);
+ tsize = sizeof(stats_t) * (NUM_DC_TYPE + 1);
stats_yearly = malloc(size);
stats_monthly = malloc(size);
stats_by_trip = malloc(size);
- stats_by_type = malloc(size);
+ stats_by_type = malloc(tsize);
if (!stats_yearly || !stats_monthly || !stats_by_trip || !stats_by_type)
return;
memset(stats_yearly, 0, size);
memset(stats_monthly, 0, size);
memset(stats_by_trip, 0, size);
- memset(stats_by_type, 0, size);
+ memset(stats_by_type, 0, tsize);
stats_yearly[0].is_year = true;
/* Setting the is_trip to true to show the location as first