From bc1f78c8bd2ac21e471c444ecac8601489522172 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 25 Mar 2022 19:21:02 +0100 Subject: [PATCH] More sanitizer fixes --- CMakeLists.txt | 1 + src/Battling/Flow/ChoiceQueue.cpp | 3 +++ src/Battling/Models/CreateCreature.cpp | 2 +- src/Battling/Models/Creature.hpp | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dbef6cb..d0d8e6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,6 +129,7 @@ if (CREATURELIB_TESTS) # Add a definition for the test library target_compile_definitions(CreatureLibTests PRIVATE TESTS_BUILD) if (SANITIZER_TESTS AND NOT WINDOWS) + target_compile_options(CreatureLib PRIVATE -fsanitize=address,undefined,leak,integer,nullability -fno-sanitize-recover=all) target_compile_options(CreatureLibTests PRIVATE -fsanitize=address,undefined,leak,integer,nullability -fno-sanitize-recover=all) target_link_options(CreatureLibTests PRIVATE -fsanitize=address,undefined,leak,integer,nullability -fno-sanitize-recover=all) endif () diff --git a/src/Battling/Flow/ChoiceQueue.cpp b/src/Battling/Flow/ChoiceQueue.cpp index 506e09d..8d9a5df 100644 --- a/src/Battling/Flow/ChoiceQueue.cpp +++ b/src/Battling/Flow/ChoiceQueue.cpp @@ -22,6 +22,9 @@ bool CreatureLib::Battling::ChoiceQueue::MoveCreatureChoiceNext(CreatureLib::Bat for (size_t i = choiceIndex - 1; i >= _current && i != SIZE_MAX; i--) { // Place everything in one spot later. _queue[i + 1] = _queue[i]; + if (i == 0) { + break; + } } // Set the creature choice up next. _queue[_current] = creatureChoice; diff --git a/src/Battling/Models/CreateCreature.cpp b/src/Battling/Models/CreateCreature.cpp index 9b87632..755d359 100644 --- a/src/Battling/Models/CreateCreature.cpp +++ b/src/Battling/Models/CreateCreature.cpp @@ -40,7 +40,7 @@ Creature* CreateCreature::Create() { } auto identifier = this->_identifier; if (identifier == 0) { - identifier = rand.Get(); + identifier = rand.GetUnsigned(); } auto gender = this->_gender; if (gender == static_cast(-1)) { diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 231b4a7..164dcec 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -34,7 +34,7 @@ namespace CreatureLib::Battling { Library::Gender _gender; u8 _coloring; - u32 _currentHealth = -1; + u32 _currentHealth = 0; f32 _weight; f32 _height;