From 6f63d430b089908c85446dbe9c2d0e2ab3acb591 Mon Sep 17 00:00:00 2001 From: jackpoz Date: Tue, 8 Oct 2013 20:38:42 +0200 Subject: Tools/MeshExtractor: Fix uninitialized values Fix uninitialized struct padding bytes written to output files. These bytes are actually ignored when loading these files, so the main point of this fix is to shut up the Valgrind log. Valgrind log: Syscall param write(buf) points to uninitialised byte(s) at : ??? (syscall-template.S:81) by : _IO_file_write@@GLIBC_2.2.5 (fileops.c:1270) by : new_do_write (fileops.c:546) by : _IO_do_write@@GLIBC_2.2.5 (fileops.c:519) by : _IO_file_xsputn@@GLIBC_2.2.5 (fileops.c:1341) by : fwrite (iofwrite.c:43) by BuilderThread::svc() (ContinentBuilder.cpp:56) by : ACE_Task_Base::svc_run(void*) (in /usr/lib/libACE-6.0.3.so) by : ACE_Thread_Adapter::invoke_i() (in /usr/lib/libACE-6.0.3.so) by : ACE_Thread_Adapter::invoke() (in /usr/lib/libACE-6.0.3.so) by : start_thread (pthread_create.c:311) by : clone (clone.S:113) Address 0x4039011 is not stack'd, malloc'd or (recently) free'd Uninitialised value was created by a stack allocation at: BuilderThread::svc() (ContinentBuilder.cpp:30) --- src/tools/mesh_extractor/ContinentBuilder.cpp | 2 ++ src/tools/mesh_extractor/Utils.cpp | 10 ++++++++++ src/tools/mesh_extractor/Utils.h | 6 ++---- 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/tools/mesh_extractor/ContinentBuilder.cpp b/src/tools/mesh_extractor/ContinentBuilder.cpp index 5130f467403..b4b29325171 100644 --- a/src/tools/mesh_extractor/ContinentBuilder.cpp +++ b/src/tools/mesh_extractor/ContinentBuilder.cpp @@ -58,6 +58,7 @@ public: return 0; } MmapTileHeader header; + Utils::InitializeMmapTileHeader(header); header.size = builder.DataSize; fwrite(&header, sizeof(MmapTileHeader), 1, f); fwrite(nav, sizeof(unsigned char), builder.DataSize, f); @@ -149,6 +150,7 @@ void ContinentBuilder::Build() } MmapTileHeader mheader; + Utils::InitializeMmapTileHeader(mheader); mheader.size = builder->DataSize; fwrite(&mheader, sizeof(MmapTileHeader), 1, f); fwrite(nav, sizeof(unsigned char), builder->DataSize, f); diff --git a/src/tools/mesh_extractor/Utils.cpp b/src/tools/mesh_extractor/Utils.cpp index d533c37f9f7..255362d0e9c 100644 --- a/src/tools/mesh_extractor/Utils.cpp +++ b/src/tools/mesh_extractor/Utils.cpp @@ -455,3 +455,13 @@ WMOGroupHeader WMOGroupHeader::Read(Stream* stream) return ret; } + +void Utils::InitializeMmapTileHeader(MmapTileHeader& header) +{ + memset(&header, 0, sizeof(MmapTileHeader)); + header.mmapMagic = MMAP_MAGIC; + header.dtVersion = DT_NAVMESH_VERSION; + header.mmapVersion = MMAP_VERSION; + header.size = 0; + header.usesLiquids = true; +} diff --git a/src/tools/mesh_extractor/Utils.h b/src/tools/mesh_extractor/Utils.h index 45cfc6cfd4b..231aa181e01 100644 --- a/src/tools/mesh_extractor/Utils.h +++ b/src/tools/mesh_extractor/Utils.h @@ -344,10 +344,7 @@ struct MmapTileHeader uint32 dtVersion; uint32 mmapVersion; uint32 size; - bool usesLiquids; - - MmapTileHeader() : mmapMagic(MMAP_MAGIC), dtVersion(DT_NAVMESH_VERSION), - mmapVersion(MMAP_VERSION), size(0), usesLiquids(true) {} + bool usesLiquids : 1; }; class Utils @@ -386,5 +383,6 @@ public: static Vector3 TransformDoodadVertex(const IDefinition& def, Vector3 vec, bool translate = true); static Vector3 VectorTransform(const Vector3& vec, const G3D::Matrix4& matrix, bool normal = false); static Vector3 TransformWmoDoodad(const DoodadInstance& inst, const WorldModelDefinition& root, Vector3& vec, bool translate = true); + static void InitializeMmapTileHeader(MmapTileHeader& header); }; #endif -- cgit v1.2.3