diff --git a/include/assimp/Hash.h b/include/assimp/Hash.h index 5a02f5f31..18bd270f5 100644 --- a/include/assimp/Hash.h +++ b/include/assimp/Hash.h @@ -48,6 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include // ------------------------------------------------------------------------------------------------ // Hashing function taken from @@ -73,9 +74,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ------------------------------------------------------------------------------------------------ inline uint32_t SuperFastHash (const char * data, uint32_t len = 0, uint32_t hash = 0) { -uint32_t tmp; -int rem; -size_t offset; + uint32_t tmp; + int rem; if (!data) return 0; if (!len)len = (uint32_t)::strlen(data); @@ -96,11 +96,7 @@ size_t offset; switch (rem) { case 3: hash += get16bits (data); hash ^= hash << 16; - offset = static_cast(sizeof(uint16_t)); - if (offset < 0) { - return 0; - } - hash ^= data[offset] << 18; + hash ^= abs(data[sizeof(uint16_t)]) << 18; hash += hash >> 11; break; case 2: hash += get16bits (data); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3fc1c8a84..cdf13d778 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,5 @@ # Open Asset Import Library (assimp) # ---------------------------------------------------------------------- -# # Copyright (c) 2006-2022, assimp team # # All rights reserved. @@ -72,6 +71,7 @@ SET( COMMON unit/AssimpAPITest_aiQuaternion.cpp unit/AssimpAPITest_aiVector2D.cpp unit/AssimpAPITest_aiVector3D.cpp + unit/Common/utHash.cpp unit/MathTest.cpp unit/MathTest.h unit/RandomNumberGeneration.h diff --git a/test/unit/Common/utHash.cpp b/test/unit/Common/utHash.cpp new file mode 100644 index 000000000..82f9b8501 --- /dev/null +++ b/test/unit/Common/utHash.cpp @@ -0,0 +1,56 @@ +/* +--------------------------------------------------------------------------- +Open Asset Import Library (assimp) +--------------------------------------------------------------------------- + +Copyright (c) 2006-2022, assimp team + +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the following +conditions are met: + +* Redistributions of source code must retain the above +copyright notice, this list of conditions and the +following disclaimer. + +* Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the +following disclaimer in the documentation and/or other +materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its +contributors may be used to endorse or promote products +derived from this software without specific prior +written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--------------------------------------------------------------------------- +*/ + +#include "UnitTestPCH.h" + +#include + +using namespace Assimp; + +class utHash : public ::testing::Test { + // empty +}; + +TEST_F( utHash, SuperFastHashTest ) { + const char *Data = "-21416115v"; + auto result = SuperFastHash(Data, 10); + EXPECT_NE(0, result); +} diff --git a/test/unit/MathTest.cpp b/test/unit/MathTest.cpp index ff870ff43..86a5d7e0f 100644 --- a/test/unit/MathTest.cpp +++ b/test/unit/MathTest.cpp @@ -5,8 +5,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2022, assimp team - - All rights reserved. Redistribution and use of this software in source and binary forms,