Skip to content

Commit

Permalink
asan: enable more asan and ubsan checks. (open-telemetry#224)
Browse files Browse the repository at this point in the history
* Don't call nullptr->f().
* Avoid signed overflow.
  • Loading branch information
g-easy authored Aug 4, 2020
1 parent 102567e commit d9035ef
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
8 changes: 6 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
build --copt -DGRPC_BAZEL_BUILD

# --config=asan : Address Sanitizer.
common:asan --copt -fsanitize=address
common:asan --copt -DADDRESS_SANITIZER
common:asan --linkopt -fsanitize=address
common:asan --copt -fsanitize=address,bool,float-cast-overflow,integer-divide-by-zero,null,return,returns-nonnull-attribute,shift-exponent,signed-integer-overflow,unreachable,vla-bound
common:asan --copt -fsanitize-address-use-after-scope
common:asan --copt -fno-sanitize-recover=all
common:asan --linkopt -fsanitize=address,bool,float-cast-overflow,integer-divide-by-zero,null,return,returns-nonnull-attribute,shift-exponent,signed-integer-overflow,unreachable,vla-bound
common:asan --linkopt -fsanitize-address-use-after-scope
common:asan --linkopt -fno-sanitize-recover=all
common:asan --cc_output_directory_tag=asan

# --config=tsan : Thread Sanitizer.
Expand Down
2 changes: 1 addition & 1 deletion api/test/nostd/shared_ptr_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ TEST(SharedPtrTest, PointerOperators)

EXPECT_EQ(&*ptr1, value);
EXPECT_EQ(
shared_ptr<B> {}->f(), 123);
shared_ptr<B> { new B }->f(), 123);
}

TEST(SharedPtrTest, Swap)
Expand Down
5 changes: 4 additions & 1 deletion api/test/nostd/unique_ptr_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ TEST(UniquePtrTest, StdUniquePtrConversionOperator)
EXPECT_EQ(ptr1.get(), nullptr);
EXPECT_EQ(ptr2.get(), value);

ptr2 = nullptr;
EXPECT_EQ(ptr2.get(), nullptr);

EXPECT_TRUE((std::is_assignable<std::unique_ptr<int>, unique_ptr<int> &&>::value));
EXPECT_FALSE((std::is_assignable<std::unique_ptr<int>, unique_ptr<int> &>::value));
}
Expand All @@ -109,7 +112,7 @@ TEST(UniquePtrTest, PointerOperators)

EXPECT_EQ(&*ptr1, value);
EXPECT_EQ(
unique_ptr<B> {}->f(), 123);
unique_ptr<B> { new B }->f(), 123);
}

TEST(UniquePtrTest, Reset)
Expand Down
2 changes: 1 addition & 1 deletion sdk/test/metrics/counter_aggregator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ TEST(CounterAggregator, Update)
int sum = 0;
for (int i = 0; i < 100; i++)
{
int tmp = std::rand();
int tmp = std::rand() % 128;
beta.update(tmp);
sum += tmp;
}
Expand Down

0 comments on commit d9035ef

Please sign in to comment.