From 21f53fc1570996d8f84709c14a25ac428484f19e Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 25 Nov 2010 20:41:59 +0100 Subject: 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. --- src/gui/math3d/qgenericmatrix.h | 6 +++--- 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 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 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 -- cgit v0.12