Sat, 28 Jan 2017 17:20:16 +0200
Removed the dangerous C-array constructor from the matrix - no need for it anyway since the matrix already is an array of doubles.
--- a/src/addObjectDialog.cpp Sat Jan 28 17:14:05 2017 +0200 +++ b/src/addObjectDialog.cpp Sat Jan 28 17:20:16 2017 +0200 @@ -310,17 +310,14 @@ if (type == OBJ_SubfileReference) { - QStringList matrixstrvals = dlg.le_matrix->text().split (" ", QString::SkipEmptyParts); + QStringList stringValues = dlg.le_matrix->text().split (" ", QString::SkipEmptyParts); - if (countof(matrixstrvals) == 9) + if (countof(stringValues) == 9) { - double matrixvals[9]; int i = 0; - for (QString val : matrixstrvals) - matrixvals[i++] = val.toFloat(); - - transform = Matrix (matrixvals); + for (QString stringValue : stringValues) + transform.value(i++) = stringValue.toFloat(); } }
--- a/src/types/matrix.cpp Sat Jan 28 17:14:05 2017 +0200 +++ b/src/types/matrix.cpp Sat Jan 28 17:20:16 2017 +0200 @@ -27,16 +27,6 @@ m_values{0} {} /* - * Initializes the matrix from a C array - * Note: the array must have (at least) 9 values! - */ -Matrix::Matrix (double values[]) -{ - for (int i = 0; i < 9; ++i) - m_values[i] = values[i]; -} - -/* * Constructs a matrix from a single fill value. */ Matrix::Matrix (double fillvalue) : @@ -48,8 +38,15 @@ */ Matrix::Matrix (const std::initializer_list<double>& values) { - if (countof(values) == 9) - memcpy (&m_values[0], values.begin(), sizeof m_values); + int i = 0; + + for (double value : values) + { + if (i < 9) + m_values[i++] = value; + else + break; + } } /* @@ -89,7 +86,8 @@ */ void Matrix::zero() { - memset (&m_values[0], 0, sizeof m_values); + for (double& value : m_values) + value = 0; } /* @@ -103,7 +101,7 @@ for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) for (int k = 0; k < 3; ++k) - result[i][j] += (*this)[i][k] * other[k][j]; + result(i, j) += (*this)(i, k) * other(k, j); return result; }