diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2010-11-25 19:41:59 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2011-02-21 13:44:11 (GMT) |
commit | 21f53fc1570996d8f84709c14a25ac428484f19e (patch) | |
tree | acd52f790fd3c18409b78feae3a7130baeff7053 /src/gui/math3d | |
parent | 0dba7d0873a736420bb954dce423cb7933a5b3cc (diff) | |
download | Qt-21f53fc1570996d8f84709c14a25ac428484f19e.zip Qt-21f53fc1570996d8f84709c14a25ac428484f19e.tar.gz Qt-21f53fc1570996d8f84709c14a25ac428484f19e.tar.bz2 |
Fix "array subscript out of bounds" warning with GCC 4.5 in QtOpenGL
If you have:
qreal m[2][2];
const qreal *constData() { return m[0]; }
And somewhere else:
const qreal *data = matrix.constData();
for (int i = 0; i < 2 * 2; ++i)
tmp = data[i];
Then GCC "sees through" the data pointer to know that the type is
actually a qreal[2] and will complain when you access data[2] and
data[3] in the example above.
It seems to be satisfied with this return *m, even though it's exactly
the same thing. This is probably fragile.
Diffstat (limited to 'src/gui/math3d')
-rw-r--r-- | src/gui/math3d/qgenericmatrix.h | 6 | ||||
-rw-r--r-- | src/gui/math3d/qmatrix4x4.h | 6 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/gui/math3d/qgenericmatrix.h b/src/gui/math3d/qgenericmatrix.h index d9aef20..181eda8 100644 --- a/src/gui/math3d/qgenericmatrix.h +++ b/src/gui/math3d/qgenericmatrix.h @@ -79,9 +79,9 @@ public: void copyDataTo(T *values) const; - T *data() { return m[0]; } - const T *data() const { return m[0]; } - const T *constData() const { return m[0]; } + T *data() { return *m; } + const T *data() const { return *m; } + const T *constData() const { return *m; } #if !defined(Q_NO_TEMPLATE_FRIENDS) template<int NN, int MM, typename TT> diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h index 706450a..ad05116 100644 --- a/src/gui/math3d/qmatrix4x4.h +++ b/src/gui/math3d/qmatrix4x4.h @@ -173,8 +173,8 @@ public: QGenericMatrix<N, M, qreal> toGenericMatrix() const; inline qreal *data(); - inline const qreal *data() const { return m[0]; } - inline const qreal *constData() const { return m[0]; } + inline const qreal *data() const { return *m; } + inline const qreal *constData() const { return *m; } void optimize(); @@ -974,7 +974,7 @@ inline qreal *QMatrix4x4::data() // We have to assume that the caller will modify the matrix elements, // so we flip it over to "General" mode. flagBits = General; - return m[0]; + return *m; } #ifndef QT_NO_DEBUG_STREAM |