Merge pull request #4532 from assimp/kimkulling/fix_undefined_behaviour_in_superfasthast_issue4531
Add unittest to reproduce undefined behaviourpull/4537/head
commit
4d451fe437
|
@ -48,6 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Hashing function taken from
|
// 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) {
|
inline uint32_t SuperFastHash (const char * data, uint32_t len = 0, uint32_t hash = 0) {
|
||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
int rem;
|
int rem;
|
||||||
size_t offset;
|
|
||||||
|
|
||||||
if (!data) return 0;
|
if (!data) return 0;
|
||||||
if (!len)len = (uint32_t)::strlen(data);
|
if (!len)len = (uint32_t)::strlen(data);
|
||||||
|
@ -96,11 +96,7 @@ size_t offset;
|
||||||
switch (rem) {
|
switch (rem) {
|
||||||
case 3: hash += get16bits (data);
|
case 3: hash += get16bits (data);
|
||||||
hash ^= hash << 16;
|
hash ^= hash << 16;
|
||||||
offset = static_cast<size_t>(sizeof(uint16_t));
|
hash ^= abs(data[sizeof(uint16_t)]) << 18;
|
||||||
if (offset < 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
hash ^= data[offset] << 18;
|
|
||||||
hash += hash >> 11;
|
hash += hash >> 11;
|
||||||
break;
|
break;
|
||||||
case 2: hash += get16bits (data);
|
case 2: hash += get16bits (data);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# Open Asset Import Library (assimp)
|
# Open Asset Import Library (assimp)
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
#
|
|
||||||
# Copyright (c) 2006-2022, assimp team
|
# Copyright (c) 2006-2022, assimp team
|
||||||
#
|
#
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
|
@ -72,6 +71,7 @@ SET( COMMON
|
||||||
unit/AssimpAPITest_aiQuaternion.cpp
|
unit/AssimpAPITest_aiQuaternion.cpp
|
||||||
unit/AssimpAPITest_aiVector2D.cpp
|
unit/AssimpAPITest_aiVector2D.cpp
|
||||||
unit/AssimpAPITest_aiVector3D.cpp
|
unit/AssimpAPITest_aiVector3D.cpp
|
||||||
|
unit/Common/utHash.cpp
|
||||||
unit/MathTest.cpp
|
unit/MathTest.cpp
|
||||||
unit/MathTest.h
|
unit/MathTest.h
|
||||||
unit/RandomNumberGeneration.h
|
unit/RandomNumberGeneration.h
|
||||||
|
|
|
@ -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 <assimp/Hash.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2022, assimp team
|
Copyright (c) 2006-2022, assimp team
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
|
Loading…
Reference in New Issue