diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index f6649328d..8f6e957ff 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -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)) diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 21862000e..28265421a 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -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; } diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 41004198b..d61a2bfc6 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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;