Removed the dangerous C-array constructor from the matrix - no need for it anyway since the matrix already is an array of doubles.

Sat, 28 Jan 2017 17:20:16 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 28 Jan 2017 17:20:16 +0200
changeset 1069
220cde0fa2d9
parent 1068
283de3bd8b0e
child 1070
292c64cb2a75

Removed the dangerous C-array constructor from the matrix - no need for it anyway since the matrix already is an array of doubles.

src/addObjectDialog.cpp file | annotate | diff | comparison | revisions
src/types/matrix.cpp file | annotate | diff | comparison | revisions
src/types/matrix.h file | annotate | diff | comparison | revisions
--- 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;
 }
--- 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<double>& values);
 	Matrix (double fillval);
-	Matrix (double values[]);
 
 	double* begin();
 	const double* begin() const;

mercurial