Skip to content

Commit 64e61d2

Browse files
mathbunnyrudanmar
authored andcommitted
Add an ability to use address sanitizer (danmar#979)
1 parent 15d814e commit 64e61d2

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

cmake/compileroptions.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ if (USE_ANALYZE)
3232
set (CMAKE_CXX_FLAGS_RELEASE "-O2")
3333
endif()
3434

35+
set(CMAKE_CXX_FLAGS_ASAN "-g -fsanitize=address,undefined -fno-sanitize-recover=all"
36+
CACHE STRING "Compiler flags in asan build"
37+
FORCE)
38+
3539
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
3640
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
3741
if (NOT (GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6))

lib/mathlib.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ MathLib::value MathLib::value::shiftLeft(const MathLib::value &v) const
270270
if (!isInt() || !v.isInt())
271271
throw InternalError(nullptr, "Shift operand is not integer");
272272
MathLib::value ret(*this);
273+
if (v.intValue >= MathLib::bigint_bits) {
274+
return ret;
275+
}
273276
ret.intValue <<= v.intValue;
274277
return ret;
275278
}
@@ -279,6 +282,9 @@ MathLib::value MathLib::value::shiftRight(const MathLib::value &v) const
279282
if (!isInt() || !v.isInt())
280283
throw InternalError(nullptr, "Shift operand is not integer");
281284
MathLib::value ret(*this);
285+
if (v.intValue >= MathLib::bigint_bits) {
286+
return ret;
287+
}
282288
ret.intValue >>= v.intValue;
283289
return ret;
284290
}

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,7 @@ static void execute(const Token *expr,
25142514
else if (expr->str() == "%")
25152515
*result = result1 % result2;
25162516
else if (expr->str() == "<<") {
2517-
if (result2 < 0 || result1 < 0) { // don't perform UB
2517+
if (result2 < 0 || result1 < 0 || result2 >= MathLib::bigint_bits) { // don't perform UB
25182518
*error= true;
25192519
} else {
25202520
*result = result1 << result2;

0 commit comments

Comments
 (0)