Add an ability to use address sanitizer (#979)

This commit is contained in:
Ayaz Salikhov 2017-10-21 22:04:14 +03:00 committed by Daniel Marjamäki
parent 15d814e609
commit 64e61d28ba
3 changed files with 11 additions and 1 deletions

View File

@ -32,6 +32,10 @@ if (USE_ANALYZE)
set (CMAKE_CXX_FLAGS_RELEASE "-O2")
endif()
set(CMAKE_CXX_FLAGS_ASAN "-g -fsanitize=address,undefined -fno-sanitize-recover=all"
CACHE STRING "Compiler flags in asan build"
FORCE)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (NOT (GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6))

View File

@ -270,6 +270,9 @@ MathLib::value MathLib::value::shiftLeft(const MathLib::value &v) const
if (!isInt() || !v.isInt())
throw InternalError(nullptr, "Shift operand is not integer");
MathLib::value ret(*this);
if (v.intValue >= MathLib::bigint_bits) {
return ret;
}
ret.intValue <<= v.intValue;
return ret;
}
@ -279,6 +282,9 @@ MathLib::value MathLib::value::shiftRight(const MathLib::value &v) const
if (!isInt() || !v.isInt())
throw InternalError(nullptr, "Shift operand is not integer");
MathLib::value ret(*this);
if (v.intValue >= MathLib::bigint_bits) {
return ret;
}
ret.intValue >>= v.intValue;
return ret;
}

View File

@ -2514,7 +2514,7 @@ static void execute(const Token *expr,
else if (expr->str() == "%")
*result = result1 % result2;
else if (expr->str() == "<<") {
if (result2 < 0 || result1 < 0) { // don't perform UB
if (result2 < 0 || result1 < 0 || result2 >= MathLib::bigint_bits) { // don't perform UB
*error= true;
} else {
*result = result1 << result2;