# HG changeset patch # User Teemu Piippo # Date 1485616816 -7200 # Node ID 220cde0fa2d9a40f5a20800aba860e67a46fdc5a # Parent 283de3bd8b0e33c8a84d30f533a88a463199b50a Removed the dangerous C-array constructor from the matrix - no need for it anyway since the matrix already is an array of doubles. diff -r 283de3bd8b0e -r 220cde0fa2d9 src/addObjectDialog.cpp --- 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(); } } diff -r 283de3bd8b0e -r 220cde0fa2d9 src/types/matrix.cpp --- 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& 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; } diff -r 283de3bd8b0e -r 220cde0fa2d9 src/types/matrix.h --- a/src/types/matrix.h Sat Jan 28 17:14:05 2017 +0200 +++ b/src/types/matrix.h Sat Jan 28 17:20:16 2017 +0200 @@ -31,7 +31,6 @@ Matrix(); Matrix (const std::initializer_list& values); Matrix (double fillval); - Matrix (double values[]); double* begin(); const double* begin() const;