Skip to content
Permalink
Browse files

qgs3dsceneexporter.cpp: avoid cppcheck 'The address of local variable…

… 'v' might be accessed at non-zero index' false-positive by making code clearer
  • Loading branch information
rouault committed Oct 1, 2020
1 parent 09f84eb commit 2024a96e3d46a0362dfb7902fad6e0c31c014055
Showing with 7 additions and 13 deletions.
  1. +7 −13 src/3d/qgs3dsceneexporter.cpp
@@ -80,7 +80,7 @@
#include <numeric>

template<typename T>
QVector<T> getAttributeData( Qt3DRender::QAttribute *attribute, QByteArray data )
QVector<T> getAttributeData( Qt3DRender::QAttribute *attribute, const QByteArray &data )
{
uint bytesOffset = attribute->byteOffset();
uint bytesStride = attribute->byteStride();
@@ -93,40 +93,34 @@ QVector<T> getAttributeData( Qt3DRender::QAttribute *attribute, QByteArray data
return result;
}

const char *pData = data.constData();
for ( int i = bytesOffset; i < data.size(); i += bytesStride )
{
for ( unsigned int j = 0; j < vertexSize * sizeof( T ); j += sizeof( T ) )
{
// maybe a problem with endienness can happen?
T v;
char *vArr = ( char * )&v;
for ( unsigned int k = 0; k < sizeof( T ); ++k )
{
vArr[k] = data.at( i + j + k );
}
memcpy( &v, pData + i + j, sizeof( T ) );
result.push_back( v );
}
}
return result;
}

template<typename T>
QVector<uint> _getIndexDataImplementation( QByteArray data )
QVector<uint> _getIndexDataImplementation( const QByteArray &data )
{
QVector<uint> result;
const char *pData = data.constData();
for ( int i = 0; i < data.size(); i += sizeof( T ) )
{
// maybe a problem with indienness can happen?
T v;
char *vArr = ( char * )&v;
for ( unsigned long k = 0; k < sizeof( T ); ++k )
vArr[k] = data.at( i + k );
memcpy( &v, pData + i, sizeof( T ) );
result.push_back( ( uint ) v );
}
return result;
}

QVector<uint> getIndexData( Qt3DRender::QAttribute *indexAttribute, QByteArray data )
QVector<uint> getIndexData( Qt3DRender::QAttribute *indexAttribute, const QByteArray &data )
{
switch ( indexAttribute->vertexBaseType() )
{

0 comments on commit 2024a96

Please sign in to comment.
You can’t perform that action at this time.