From 703d046fd9baf6f70ce78c96a1567e9675a884eb Mon Sep 17 00:00:00 2001 From: Giuseppe Barbieri Date: Sat, 18 Nov 2017 00:34:00 +0100 Subject: [PATCH 1/9] Update ValidateDataStructure.cpp --- code/ValidateDataStructure.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/ValidateDataStructure.cpp b/code/ValidateDataStructure.cpp index f1035e441..c036eac18 100644 --- a/code/ValidateDataStructure.cpp +++ b/code/ValidateDataStructure.cpp @@ -334,28 +334,28 @@ void ValidateDSProcess::Validate( const aiMesh* pMesh) case 1: if (0 == (pMesh->mPrimitiveTypes & aiPrimitiveType_POINT)) { - ReportError("aiMesh::mFaces[%i] is a POINT but aiMesh::mPrimtiveTypes " + ReportError("aiMesh::mFaces[%i] is a POINT but aiMesh::mPrimitiveTypes " "does not report the POINT flag",i); } break; case 2: if (0 == (pMesh->mPrimitiveTypes & aiPrimitiveType_LINE)) { - ReportError("aiMesh::mFaces[%i] is a LINE but aiMesh::mPrimtiveTypes " + ReportError("aiMesh::mFaces[%i] is a LINE but aiMesh::mPrimitiveTypes " "does not report the LINE flag",i); } break; case 3: if (0 == (pMesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE)) { - ReportError("aiMesh::mFaces[%i] is a TRIANGLE but aiMesh::mPrimtiveTypes " + ReportError("aiMesh::mFaces[%i] is a TRIANGLE but aiMesh::mPrimitiveTypes " "does not report the TRIANGLE flag",i); } break; default: if (0 == (pMesh->mPrimitiveTypes & aiPrimitiveType_POLYGON)) { - this->ReportError("aiMesh::mFaces[%i] is a POLYGON but aiMesh::mPrimtiveTypes " + this->ReportError("aiMesh::mFaces[%i] is a POLYGON but aiMesh::mPrimitiveTypes " "does not report the POLYGON flag",i); } break; From 40bb3f3d0f7998588273565d6eee1853f4593f9a Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Fri, 17 Nov 2017 13:56:53 +0200 Subject: [PATCH 2/9] Unit test: Fix signed/unsigned comparison warnings --- test/unit/utObjImportExport.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/unit/utObjImportExport.cpp b/test/unit/utObjImportExport.cpp index 6361813d0..d9df779ac 100644 --- a/test/unit/utObjImportExport.cpp +++ b/test/unit/utObjImportExport.cpp @@ -294,12 +294,12 @@ TEST_F(utObjImportExport, relative_indices_Test) { const aiScene *scene = myimporter.ReadFileFromMemory(ObjModel.c_str(), ObjModel.size(), aiProcess_ValidateDataStructure); EXPECT_NE(nullptr, scene); - EXPECT_EQ(scene->mNumMeshes, 1); + EXPECT_EQ(scene->mNumMeshes, 1U); const aiMesh *mesh = scene->mMeshes[0]; - EXPECT_EQ(mesh->mNumVertices, 4); - EXPECT_EQ(mesh->mNumFaces, 1); + EXPECT_EQ(mesh->mNumVertices, 4U); + EXPECT_EQ(mesh->mNumFaces, 1U); const aiFace face = mesh->mFaces[0]; - EXPECT_EQ(face.mNumIndices, 4); + EXPECT_EQ(face.mNumIndices, 4U); for (unsigned int i = 0; i < face.mNumIndices; ++i) { EXPECT_EQ(face.mIndices[i], i); @@ -318,12 +318,12 @@ TEST_F(utObjImportExport, homogeneous_coordinates_Test) { const aiScene *scene = myimporter.ReadFileFromMemory(ObjModel.c_str(), ObjModel.size(), aiProcess_ValidateDataStructure); EXPECT_NE(nullptr, scene); - EXPECT_EQ(scene->mNumMeshes, 1); + EXPECT_EQ(scene->mNumMeshes, 1U); const aiMesh *mesh = scene->mMeshes[0]; - EXPECT_EQ(mesh->mNumVertices, 3); - EXPECT_EQ(mesh->mNumFaces, 1); + EXPECT_EQ(mesh->mNumVertices, 3U); + EXPECT_EQ(mesh->mNumFaces, 1U); const aiFace face = mesh->mFaces[0]; - EXPECT_EQ(face.mNumIndices, 3); + EXPECT_EQ(face.mNumIndices, 3U); const aiVector3D vertice = mesh->mVertices[0]; EXPECT_EQ(vertice.x, -1.0f); EXPECT_EQ(vertice.y, 0.0f); From c1515db56f951cec82dbfa35265db35d7d8bfd71 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 18 Nov 2017 15:50:56 +0200 Subject: [PATCH 3/9] Blender: Fix strict-aliasing warnings --- code/BlenderScene.cpp | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/code/BlenderScene.cpp b/code/BlenderScene.cpp index b9068329b..0e1dec7f3 100644 --- a/code/BlenderScene.cpp +++ b/code/BlenderScene.cpp @@ -59,7 +59,9 @@ template <> void Structure :: Convert ( { ReadField(dest.id,"id",db); - ReadField((int&)dest.type,"type",db); + int temp = 0; + ReadField(temp,"type",db); + dest.type = static_cast(temp); ReadFieldArray2(dest.obmat,"obmat",db); ReadFieldArray2(dest.parentinv,"parentinv",db); ReadFieldArray(dest.parsubstr,"parsubstr",db); @@ -100,14 +102,21 @@ template <> void Structure :: Convert ( ) const { - ReadField((short&)dest.mapto,"mapto",db); - ReadField((int&)dest.blendtype,"blendtype",db); + int temp_short = 0; + ReadField(temp_short,"mapto",db); + dest.mapto = static_cast(temp_short); + int temp = 0; + ReadField(temp,"blendtype",db); + dest.blendtype = static_cast(temp); ReadFieldPtr(dest.object,"*object",db); ReadFieldPtr(dest.tex,"*tex",db); ReadFieldArray(dest.uvname,"uvname",db); - ReadField((int&)dest.projx,"projx",db); - ReadField((int&)dest.projy,"projy",db); - ReadField((int&)dest.projz,"projz",db); + ReadField(temp,"projx",db); + dest.projx = static_cast(temp); + ReadField(temp,"projy",db); + dest.projy = static_cast(temp); + ReadField(temp,"projz",db); + dest.projx = static_cast(temp); ReadField(dest.mapping,"mapping",db); ReadFieldArray(dest.ofs,"ofs",db); ReadFieldArray(dest.size,"size",db); @@ -190,7 +199,9 @@ template <> void Structure :: Convert ( { ReadField(dest.id,"id",db); - ReadField((int&)dest.type,"type",db); + int temp = 0; + ReadField(temp,"type",db); + dest.type = static_cast(temp); ReadField(dest.flags,"flags",db); ReadField(dest.colormodel,"colormodel",db); ReadField(dest.totex,"totex",db); @@ -204,7 +215,8 @@ template <> void Structure :: Convert ( ReadField(dest.spotblend,"spotblend",db); ReadField(dest.att1,"att1",db); ReadField(dest.att2,"att2",db); - ReadField((int&)dest.falloff_type,"falloff_type",db); + ReadField(temp,"falloff_type",db); + dest.falloff_type = static_cast(temp); ReadField(dest.sun_brightness,"sun_brightness",db); ReadField(dest.area_size,"area_size",db); ReadField(dest.area_sizey,"area_sizey",db); @@ -693,8 +705,12 @@ template <> void Structure :: Convert ( const FileDatabase& db ) const { - ReadField((short&)dest.imaflag,"imaflag",db); - ReadField((int&)dest.type,"type",db); + short temp_short = 0; + ReadField(temp_short,"imaflag",db); + dest.imaflag = static_cast(temp_short); + int temp = 0; + ReadField(temp,"type",db); + dest.type = static_cast(temp); ReadFieldPtr(dest.ima,"*ima",db); db.reader->IncPtr(size); @@ -708,8 +724,11 @@ template <> void Structure :: Convert ( { ReadField(dest.id,"id",db); - ReadField((int&)dest.type,"type",db); - ReadField((int&)dest.flag,"flag",db); + int temp = 0; + ReadField(temp,"type",db); + dest.type = static_cast(temp); + ReadField(temp,"flag",db); + dest.flag = static_cast(temp); ReadField(dest.lens,"lens",db); ReadField(dest.sensor_x,"sensor_x",db); ReadField(dest.clipsta,"clipsta",db); From 1067ae4bfa21bd27131f5a332b4f0c615477a97c Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 18 Nov 2017 15:54:40 +0200 Subject: [PATCH 4/9] FIReader: Fix strict-aliasing warnings --- code/FIReader.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/code/FIReader.cpp b/code/FIReader.cpp index fdf6b8a83..f3cf3cdb4 100755 --- a/code/FIReader.cpp +++ b/code/FIReader.cpp @@ -485,7 +485,9 @@ struct FIFloatDecoder: public FIDecoder { value.reserve(numFloats); for (size_t i = 0; i < numFloats; ++i) { int v = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; - value.push_back(*(float*)&v); + float f; + memcpy(&f, &v, 4); + value.push_back(f); data += 4; } return FIFloatValue::create(std::move(value)); @@ -503,7 +505,9 @@ struct FIDoubleDecoder: public FIDecoder { for (size_t i = 0; i < numDoubles; ++i) { long long b0 = data[0], b1 = data[1], b2 = data[2], b3 = data[3], b4 = data[4], b5 = data[5], b6 = data[6], b7 = data[7]; long long v = (b0 << 56) | (b1 << 48) | (b2 << 40) | (b3 << 32) | (b4 << 24) | (b5 << 16) | (b6 << 8) | b7; - value.push_back(*(double*)&v); + double f; + memcpy(&f, &v, 8); + value.push_back(f); data += 8; } return FIDoubleValue::create(std::move(value)); From 53119e74f81e06429d82e9ee2882322267af4a59 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 18 Nov 2017 15:59:30 +0200 Subject: [PATCH 5/9] Open3DGC: Fix strict-aliasing warnings --- contrib/Open3DGC/o3dgcBinaryStream.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/contrib/Open3DGC/o3dgcBinaryStream.h b/contrib/Open3DGC/o3dgcBinaryStream.h index 19e3df973..b7b7678b7 100644 --- a/contrib/Open3DGC/o3dgcBinaryStream.h +++ b/contrib/Open3DGC/o3dgcBinaryStream.h @@ -231,7 +231,8 @@ namespace o3dgc float ReadFloat32Bin(unsigned long & position) const { unsigned long value = ReadUInt32Bin(position); - float fvalue = *((float *)(&value)); + float fvalue; + memcpy(&fvalue, &value, 4); return fvalue; } unsigned long ReadUInt32Bin(unsigned long & position) const @@ -261,7 +262,8 @@ namespace o3dgc void WriteFloat32ASCII(float value) { - unsigned long uiValue = *((unsigned long *)(&value)); + unsigned long uiValue; + memcpy(&uiValue, &value, 4); WriteUInt32ASCII(uiValue); } void WriteUInt32ASCII(unsigned long position, unsigned long value) @@ -314,7 +316,8 @@ namespace o3dgc float ReadFloat32ASCII(unsigned long & position) const { unsigned long value = ReadUInt32ASCII(position); - float fvalue = *((float *)(&value)); + float fvalue; + memcpy(&fvalue, &value, 4); return fvalue; } unsigned long ReadUInt32ASCII(unsigned long & position) const From 10f4b6f95c318e92b40e1e79ff09a2eca511f136 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 18 Nov 2017 16:02:53 +0200 Subject: [PATCH 6/9] assimp_cmd: Fix strict-aliasing warnings --- tools/assimp_cmd/WriteDumb.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/assimp_cmd/WriteDumb.cpp b/tools/assimp_cmd/WriteDumb.cpp index 69d4efcc5..e1b104d40 100644 --- a/tools/assimp_cmd/WriteDumb.cpp +++ b/tools/assimp_cmd/WriteDumb.cpp @@ -177,6 +177,17 @@ inline uint32_t Write(const aiVector3D& v) return t; } +// ----------------------------------------------------------------------------------- +// Serialize a color value +template <> +inline uint32_t Write(const aiColor3D& v) +{ + uint32_t t = Write(v.r); + t += Write(v.g); + t += Write(v.b); + return t; +} + // ----------------------------------------------------------------------------------- // Serialize a color value template <> @@ -566,9 +577,9 @@ uint32_t WriteBinaryLight(const aiLight* l) len += Write(l->mAttenuationQuadratic); } - len += Write((const aiVector3D&)l->mColorDiffuse); - len += Write((const aiVector3D&)l->mColorSpecular); - len += Write((const aiVector3D&)l->mColorAmbient); + len += Write(l->mColorDiffuse); + len += Write(l->mColorSpecular); + len += Write(l->mColorAmbient); if (l->mType == aiLightSource_SPOT) { len += Write(l->mAngleInnerCone); From bcffa28a336b4ce9350b2159649fe5258aedbca7 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 18 Nov 2017 16:39:43 +0200 Subject: [PATCH 7/9] MDLImporter: Don't take address of packed struct member --- code/MDLMaterialLoader.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/MDLMaterialLoader.cpp b/code/MDLMaterialLoader.cpp index 91dcb49cc..9086925aa 100644 --- a/code/MDLMaterialLoader.cpp +++ b/code/MDLMaterialLoader.cpp @@ -665,7 +665,9 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7( if (0.0f != pcMatIn->Power) { iShadingMode = (int)aiShadingMode_Phong; - pcMatOut->AddProperty(&pcMatIn->Power,1,AI_MATKEY_SHININESS); + // pcMatIn is packed, we can't form pointers to its members + float power = pcMatIn->Power; + pcMatOut->AddProperty(&power,1,AI_MATKEY_SHININESS); } pcMatOut->AddProperty(&iShadingMode,1,AI_MATKEY_SHADING_MODEL); } From 2c8cc1f73249246d183d3e4d1aa84b4a3325f6ef Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 18 Nov 2017 16:49:03 +0200 Subject: [PATCH 8/9] BlenderDNA: Silence warning about uninitialized member --- code/BlenderDNA.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/code/BlenderDNA.h b/code/BlenderDNA.h index 4c7d0fc26..bac8d78bc 100644 --- a/code/BlenderDNA.h +++ b/code/BlenderDNA.h @@ -92,6 +92,12 @@ struct Error : DeadlyImportError { * descendents. It serves as base class for all data structure fields. */ // ------------------------------------------------------------------------------- struct ElemBase { + ElemBase() + : dna_type(nullptr) + { + // empty + } + virtual ~ElemBase() { // empty } From 8ae723165439087a6f45776b397fff03bcc550da Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 18 Nov 2017 16:50:45 +0200 Subject: [PATCH 9/9] Blender: Silence warning about uninitialized member --- code/BlenderScene.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/code/BlenderScene.h b/code/BlenderScene.h index 36094eabd..86ab1f30c 100644 --- a/code/BlenderScene.h +++ b/code/BlenderScene.h @@ -225,6 +225,14 @@ struct TFace : ElemBase { // ------------------------------------------------------------------------------- struct MTFace : ElemBase { + MTFace() + : flag(0) + , mode(0) + , tile(0) + , unwrap(0) + { + } + float uv[4][2] FAIL; char flag; short mode;