Merge pull request #1480 from turol/ubsan

Undefined Behavior sanitizer
pull/1497/head
turol 2017-10-14 19:25:43 +03:00 committed by GitHub
commit 82b269c424
6 changed files with 24 additions and 4 deletions

View File

@ -26,6 +26,10 @@ function generate()
OPTIONS="$OPTIONS -DASSIMP_ASAN=OFF"
fi
if [ "$UBSAN" = "ON" ] ; then
OPTIONS="$OPTIONS -DASSIMP_UBSAN=ON"
fi
cmake -G "Unix Makefiles" $OPTIONS
}

View File

@ -46,6 +46,9 @@ matrix:
- os: linux
compiler: clang
env: ASAN=ON
- os: linux
compiler: clang
env: UBSAN=ON
- os: linux
compiler: clang
env: SHARED_BUILD=ON

View File

@ -86,6 +86,10 @@ OPTION ( ASSIMP_ASAN
"Enable AddressSanitizer."
OFF
)
OPTION ( ASSIMP_UBSAN
"Enable Undefined Behavior sanitizer."
OFF
)
OPTION ( SYSTEM_IRRXML
"Use system installed Irrlicht/IrrXML library."
OFF
@ -234,6 +238,12 @@ if (ASSIMP_ASAN)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
endif()
if (ASSIMP_UBSAN)
MESSAGE(STATUS "Undefined Behavior sanitizer enabled")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fno-sanitize-recover=all")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fno-sanitize-recover=all")
endif()
INCLUDE (FindPkgMacros)
INCLUDE (PrecompiledHeader)

View File

@ -171,7 +171,8 @@ int B3DImporter::ReadByte(){
// ------------------------------------------------------------------------------------------------
int B3DImporter::ReadInt(){
if( _pos+4<=_buf.size() ){
int n=*(int*)&_buf[_pos];
int n;
memcpy(&n, &_buf[_pos], 4);
_pos+=4;
return n;
}
@ -182,7 +183,8 @@ int B3DImporter::ReadInt(){
// ------------------------------------------------------------------------------------------------
float B3DImporter::ReadFloat(){
if( _pos+4<=_buf.size() ){
float n=*(float*)&_buf[_pos];
float n;
memcpy(&n, &_buf[_pos], 4);
_pos+=4;
return n;
}

View File

@ -151,7 +151,8 @@ uint32_t ReadWord(const char* input, const char*& cursor, const char* end)
TokenizeError("cannot ReadWord, out of bounds",input, cursor);
}
uint32_t word = *reinterpret_cast<const uint32_t*>(cursor);
uint32_t word;
memcpy(&word, cursor, 4);
AI_SWAP4(word);
cursor += k_to_read;

View File

@ -272,7 +272,6 @@ bool IntersectsBoundaryProfile(const IfcVector3& e0, const IfcVector3& e1, const
const IfcVector3& b0 = boundary[i];
const IfcVector3& b1 = boundary[(i + 1) % bcount];
IfcVector3 b = b1 - b0;
IfcFloat b_sqlen_inv = 1.0 / b.SquareLength();
// segment-segment intersection
// solve b0 + b*s = e0 + e*t for (s,t)
@ -281,6 +280,7 @@ bool IntersectsBoundaryProfile(const IfcVector3& e0, const IfcVector3& e1, const
// no solutions (parallel lines)
continue;
}
IfcFloat b_sqlen_inv = 1.0 / b.SquareLength();
const IfcFloat x = b0.x - e0.x;
const IfcFloat y = b0.y - e0.y;