[Mesa-dev] [PATCH] mesa: Fix wrong sizeof argument in _math_matrix_copy.
Jose Fonseca
jfonseca at vmware.com
Mon Jul 30 07:25:12 PDT 2012
----- Original Message -----
> On Sun, Jul 29, 2012 at 6:54 PM, Vinson Lee <vlee at freedesktop.org>
> wrote:
> > Fixes Coverity wrong sizeof argument defect.
> >
> > Signed-off-by: Vinson Lee <vlee at freedesktop.org>
> > ---
> > src/mesa/math/m_matrix.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/src/mesa/math/m_matrix.c b/src/mesa/math/m_matrix.c
> > index 40f9229..7c4e9fd 100644
> > --- a/src/mesa/math/m_matrix.c
> > +++ b/src/mesa/math/m_matrix.c
> > @@ -1437,7 +1437,7 @@ void
> > _math_matrix_copy( GLmatrix *to, const GLmatrix *from )
> > {
> > memcpy( to->m, from->m, sizeof(Identity) );
> > - memcpy(to->inv, from->inv, sizeof(from->inv));
> > + memcpy(to->inv, from->inv, sizeof(*from->inv));
> > to->flags = from->flags;
> > to->type = from->type;
> > }
>
> It would probably be good to update the preceding line as well. It's
> kind of weird to use sizeof(X) when X isn't the source or dest to the
> memcpy().
Now you mention it, there is a reason for it.
This is the definition of GLmatrix:
typedef struct {
GLfloat *m; /**< 16 matrix elements (16-byte aligned) */
GLfloat *inv; /**< optional 16-element inverse (16-byte aligned) */
GLuint flags; /**< possible values determined by (of \link
* MatFlags MAT_FLAG_* flags\endlink)
*/
enum GLmatrixtype type;
} GLmatrix;
Therefore
memcpy(to->inv, from->inv, sizeof(from->inv));
or
memcpy(to->inv, from->inv, sizeof(*from->inv));
are busted, as none properly copies the full 16 elements.
Therefore, this
memcpy(to->inv, from->inv, sizeof(Identity);
is how the memcpy should be done.
Jose
More information about the mesa-dev
mailing list