summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-08-25 12:56:41 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-08-28 07:10:09 -0700
commit25b30da2446d9daf8343c246056b207d285582e7 (patch)
tree3b2b4d7e586530938c10c79fcba25b2e0524d8f6
parent0e55739f03d15b93a678e29bb1af26ff703f0c2f (diff)
downloadsubsurface-25b30da2446d9daf8343c246056b207d285582e7.tar.gz
Profile: properly initialize plot_info structures
The create_plot_info_new() function releases old plot data. This can only work if the plot_info structure was initialized previously. The ProfileWidget2 did that by a memset, but other parts of the code did not. Therefore, introduce a init_plot_info() function and call that when generating a plot_info struct. Constructors would make this so much easier - but since this is called from C, we can't use them. Fixes #2251 Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--CHANGELOG.md2
-rw-r--r--core/profile.c11
-rw-r--r--core/profile.h1
-rw-r--r--core/save-profiledata.c2
-rw-r--r--profile-widget/profilewidget2.cpp2
-rw-r--r--profile-widget/ruleritem.cpp2
-rw-r--r--qt-models/diveplotdatamodel.cpp2
7 files changed, 18 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 64ec61ce5..810838d54 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,4 @@
-
+- Desktop: fix crash when saving subtitles or profile picture
---
* Always add new entries at the very top of this file above other existing entries and this note.
* Use this layout for new entries: `[Area]: [Details about the change] [reference thread / issue]`
diff --git a/core/profile.c b/core/profile.c
index c1bcc40fa..ff9575700 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -1319,11 +1319,22 @@ static void debug_print_profiledata(struct plot_info *pi)
#endif
/*
+ * Initialize a plot_info structure to all-zeroes
+ */
+void init_plot_info(struct plot_info *pi)
+{
+ memset(pi, 0, sizeof(*pi));
+}
+
+/*
* Create a plot-info with smoothing and ranged min/max
*
* This also makes sure that we have extra empty events on both
* sides, so that you can do end-points without having to worry
* about it.
+ *
+ * The old data will be freed. Before the first call, the plot
+ * info must be initialized with init_plot_info().
*/
void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool fast, struct deco_state *planner_ds)
{
diff --git a/core/profile.h b/core/profile.h
index 2c4a632d5..580fc8e68 100644
--- a/core/profile.h
+++ b/core/profile.h
@@ -80,6 +80,7 @@ struct ev_select {
extern void compare_samples(struct plot_data *e1, struct plot_data *e2, char *buf, int bufsize, int sum);
extern struct plot_info *analyze_plot_info(struct plot_info *pi);
+extern void init_plot_info(struct plot_info *pi);
extern void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool fast, struct deco_state *planner_ds);
extern void calculate_deco_information(struct deco_state *ds, const struct deco_state *planner_de, const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi, bool print_mode);
extern struct plot_data *get_plot_details_new(struct plot_info *pi, int time, struct membuffer *);
diff --git a/core/save-profiledata.c b/core/save-profiledata.c
index b2279148e..7802f7cd3 100644
--- a/core/save-profiledata.c
+++ b/core/save-profiledata.c
@@ -199,6 +199,7 @@ static void save_profiles_buffer(struct membuffer *b, bool select_only)
struct plot_info pi;
struct deco_state *planner_deco_state = NULL;
+ init_plot_info(&pi);
for_each_dive(i, dive) {
if (select_only && !dive->selected)
continue;
@@ -220,6 +221,7 @@ void save_subtitles_buffer(struct membuffer *b, struct dive *dive, int offset, i
struct plot_info pi;
struct deco_state *planner_deco_state = NULL;
+ init_plot_info(&pi);
create_plot_info_new(dive, &dive->dc, &pi, false, planner_deco_state);
put_format(b, "[Script Info]\n");
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp
index f3dfb8ce9..bde470fd7 100644
--- a/profile-widget/profilewidget2.cpp
+++ b/profile-widget/profilewidget2.cpp
@@ -148,7 +148,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent),
// would like to be able to ASSERT here that PreferencesDialog::loadSettings has been called.
isPlotZoomed = prefs.zoomed_plot; // now it seems that 'prefs' has loaded our preferences
- memset(&plotInfo, 0, sizeof(plotInfo));
+ init_plot_info(&plotInfo);
setupSceneAndFlags();
setupItemSizes();
diff --git a/profile-widget/ruleritem.cpp b/profile-widget/ruleritem.cpp
index f489aa9dd..3e61790ad 100644
--- a/profile-widget/ruleritem.cpp
+++ b/profile-widget/ruleritem.cpp
@@ -17,7 +17,7 @@ RulerNodeItem2::RulerNodeItem2() :
timeAxis(NULL),
depthAxis(NULL)
{
- memset(&pInfo, 0, sizeof(pInfo));
+ init_plot_info(&pInfo);
setRect(-8, -8, 16, 16);
setBrush(QColor(0xff, 0, 0, 127));
setPen(QColor(Qt::red));
diff --git a/qt-models/diveplotdatamodel.cpp b/qt-models/diveplotdatamodel.cpp
index 35490a0a3..6f718021f 100644
--- a/qt-models/diveplotdatamodel.cpp
+++ b/qt-models/diveplotdatamodel.cpp
@@ -10,7 +10,7 @@ DivePlotDataModel::DivePlotDataModel(QObject *parent) :
diveId(0),
dcNr(0)
{
- memset(&pInfo, 0, sizeof(pInfo));
+ init_plot_info(&pInfo);
memset(&plot_deco_state, 0, sizeof(struct deco_state));
}