On 14 June 2017 at 01:01, Pedro Neves <[email protected]> wrote:
> On 13-06-2017 22:43, Lubomir I. Ivanov wrote:
>
> replace it with the following:
> const int test_row = index.row();
> fprintf(stderr, "TEST_ROW: %d\n", test_row); // include <stdio.h> if needed
> struct tank_info_t *info = &tank_info[test_row];
>
> Lubomir:
>
> This is what I get now:
>
>

<snip>

> TEST_ROW: 100
> TEST_ROW: 101
> Segmentation fault (core dumped)
>

row values seem to go above 99.
please try reseting the tankinfomodel.cpp changes and apply the attached patch

(git apply test_tank_info_model_fix.patch)

and rebuild / retest.

if it works we have a "clamp" solution, but the real cause is unknown.
the QModelIndex should not return row values above the maximum size of
our tank_info buffer.

lubomir
--
diff --git a/core/dive.h b/core/dive.h
index c65d3ff..2565b4a 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -296,6 +296,7 @@ struct divecomputer {
 
 #define MAX_CYLINDERS (20)
 #define MAX_WEIGHTSYSTEMS (6)
+#define MAX_TANK_INFO (100)
 #define W_IDX_PRIMARY 0
 #define W_IDX_SECONDARY 1
 
@@ -923,7 +924,7 @@ struct tank_info_t {
 	const char *name;
 	int cuft, ml, psi, bar;
 };
-extern struct tank_info_t tank_info[100];
+extern struct tank_info_t tank_info[MAX_TANK_INFO];
 
 struct ws_info_t {
 	const char *name;
diff --git a/qt-models/tankinfomodel.cpp b/qt-models/tankinfomodel.cpp
index 75303d8..97f0e80 100644
--- a/qt-models/tankinfomodel.cpp
+++ b/qt-models/tankinfomodel.cpp
@@ -28,6 +28,10 @@ bool TankInfoModel::setData(const QModelIndex &index, const QVariant &value, int
 {
 	//WARN Seems wrong, we need to check for role == Qt::EditRole
 	Q_UNUSED(role);
+
+	if (index.row() < 0 || index.row() > MAX_TANK_INFO - 1)
+		return false;
+
 	struct tank_info_t *info = &tank_info[index.row()];
 	switch (index.column()) {
 	case DESCRIPTION:
@@ -51,7 +55,7 @@ void TankInfoModel::clear()
 QVariant TankInfoModel::data(const QModelIndex &index, int role) const
 {
 	QVariant ret;
-	if (!index.isValid()) {
+	if (!index.isValid() || index.row() < 0 || index.row() > MAX_TANK_INFO - 1) {
 		return ret;
 	}
 	if (role == Qt::FontRole) {
_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to