From 35976a4eb460632c4565234ee5d7105fc1ee2086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20M=C3=B6ller?= Date: Tue, 2 Jul 2024 21:54:18 +0200 Subject: [PATCH] fixes some uninit bool loads (#5644) This commit fixes some bool loads which are not initialized. With ubsan and the "option -fsanitize=bool", this results in a runtime error during test execution. Co-authored-by: Kim Kulling --- .../LimitBoneWeightsProcess.cpp | 3 ++- include/assimp/metadata.h | 12 +++++------ test/unit/utMetadata.cpp | 20 +++++++++++++++++-- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/code/PostProcessing/LimitBoneWeightsProcess.cpp b/code/PostProcessing/LimitBoneWeightsProcess.cpp index 816914ada..71b6f9ec6 100644 --- a/code/PostProcessing/LimitBoneWeightsProcess.cpp +++ b/code/PostProcessing/LimitBoneWeightsProcess.cpp @@ -53,7 +53,8 @@ namespace Assimp { // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer -LimitBoneWeightsProcess::LimitBoneWeightsProcess() : mMaxWeights(AI_LMW_MAX_WEIGHTS) { +LimitBoneWeightsProcess::LimitBoneWeightsProcess() : + mMaxWeights(AI_LMW_MAX_WEIGHTS), mRemoveEmptyBones(true) { // empty } diff --git a/include/assimp/metadata.h b/include/assimp/metadata.h index 8d387ca00..4fd4adf7e 100644 --- a/include/assimp/metadata.h +++ b/include/assimp/metadata.h @@ -113,19 +113,19 @@ struct aiMetadata; */ // ------------------------------------------------------------------------------- -inline aiMetadataType GetAiType(bool) { +inline aiMetadataType GetAiType(const bool &) { return AI_BOOL; } inline aiMetadataType GetAiType(int32_t) { return AI_INT32; } -inline aiMetadataType GetAiType(uint64_t) { +inline aiMetadataType GetAiType(const uint64_t &) { return AI_UINT64; } -inline aiMetadataType GetAiType(float) { +inline aiMetadataType GetAiType(const float &) { return AI_FLOAT; } -inline aiMetadataType GetAiType(double) { +inline aiMetadataType GetAiType(const double &) { return AI_DOUBLE; } inline aiMetadataType GetAiType(const aiString &) { @@ -137,10 +137,10 @@ inline aiMetadataType GetAiType(const aiVector3D &) { inline aiMetadataType GetAiType(const aiMetadata &) { return AI_AIMETADATA; } -inline aiMetadataType GetAiType(int64_t) { +inline aiMetadataType GetAiType(const int64_t &) { return AI_INT64; } -inline aiMetadataType GetAiType(uint32_t) { +inline aiMetadataType GetAiType(const uint32_t &) { return AI_UINT32; } diff --git a/test/unit/utMetadata.cpp b/test/unit/utMetadata.cpp index e7cd239aa..76afd52ef 100644 --- a/test/unit/utMetadata.cpp +++ b/test/unit/utMetadata.cpp @@ -242,6 +242,22 @@ TEST_F( utMetadata, copy_test ) { EXPECT_EQ( i32v, v ); } + // uint32_t test + { + uint32_t v = 0; + bool ok = copy.Get("uint32_t", v); + EXPECT_TRUE(ok); + EXPECT_EQ( ui32, v ); + } + + // int64_t test + { + int64_t v = -1; + bool ok = copy.Get("int64_t", v); + EXPECT_TRUE(ok); + EXPECT_EQ( i64, v ); + } + // uint64_t test { uint64_t v = 255; @@ -264,14 +280,14 @@ TEST_F( utMetadata, copy_test ) { EXPECT_EQ( dv, v ); } - // bool test + // string test { aiString v; EXPECT_TRUE( copy.Get( "aiString", v ) ); EXPECT_EQ( strVal, v ); } - // bool test + // vector test { aiVector3D v; EXPECT_TRUE( copy.Get( "aiVector3D", v ) );