Skip to content

Commit

Permalink
Merged Pull Request '#63 main->main : introduce -fsanitize=address, f…
Browse files Browse the repository at this point in the history
…ix identified problems'

introduce -fsanitize=address, fix identified problems
  • Loading branch information
Automation51D authored Dec 18, 2024
2 parents b1a48b5 + 7c53e57 commit 52db864
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,12 @@ if(BUILD_TESTING)
target_link_options(CommonTests PRIVATE "/WX")
else ()
target_compile_options(CommonTests PRIVATE ${COMMON_C_COMPILE_OPTIONS})
target_link_options(CommonTests PRIVATE "-fsanitize=address")
if (lower_CMAKE_BUILD_TYPE STREQUAL "debug")
message("-- CommonTests Linker options for code coverage")
target_link_options(CommonTests PRIVATE "-fprofile-arcs" "-ftest-coverage")
endif()

endif()

if (TESTCOVERAGE_ENABLED)
Expand Down
14 changes: 9 additions & 5 deletions tests/CollectionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class CollectionTestData {
}
virtual ~CollectionTestData() {
if (map != nullptr) {
delete map;
delete [] map;
map = nullptr;
}
if (data != nullptr) {
delete data;
delete [] data;
data = nullptr;
}
}
Expand Down Expand Up @@ -182,8 +182,12 @@ class CollectionTest : public Base {
collection = NULL;
}
~CollectionTest() {
delete data;
delete config;
if (data != NULL) {
delete data;
}
if (config != NULL) {
delete config;
}
}
virtual void SetUp() { Base::SetUp(); }
void TearDown() {
Expand Down Expand Up @@ -771,4 +775,4 @@ COLLECTION_TEST(File, Variable, Size, MixedStreamCacheConf, TEST_STRINGS_COUNT)

COLLECTION_TEST(File, Fixed, Count, MaxMemConf, TEST_STRINGS_COUNT)
COLLECTION_TEST(File, Fixed, Size, MaxMemConf, TEST_STRINGS_COUNT)
COLLECTION_TEST(File, Variable, Size, MaxMemConf, TEST_STRINGS_COUNT)
COLLECTION_TEST(File, Variable, Size, MaxMemConf, TEST_STRINGS_COUNT)
2 changes: 2 additions & 0 deletions tests/IpParserTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ TEST(ParseIp, ParseIp_Ipv6_AbbreviatedStart)
EXPECT_TRUE(
CheckResult(result->address, expected, FIFTYONE_DEGREES_IPV6_LENGTH)) <<
"The value of the abbreivated start IPv6 address is not correctly parsed.";
free(result);
}
//TEST(ParseIp, ParseIp_Ipv6_AbbreviatedMiddle)
//{
Expand Down Expand Up @@ -183,6 +184,7 @@ TEST(ParseIp, ParseIp_Invalid_ipv4OutOfRange)
CheckResult(result->address, expected, FIFTYONE_DEGREES_IPV4_LENGTH)) <<
"The value of the out of range IPv4 address is not correctly restricted "
"at 255.";
free(result);
}
//TEST(ParseIp, ParseIp_Invalid_ipv4TooMany)
//{
Expand Down
2 changes: 2 additions & 0 deletions tests/OverridesTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ TEST(OverrideProfileIdsTests, CaseSensitivity) {
fiftyoneDegreesOverrideProfileIds(evidence, &state, override);
EXPECT_EQ(5, state) <<
"Case insentivity should be honoured for ProfileIds with lower case.";

fiftyoneDegreesEvidenceFree(evidence);
}

// Check if overrides are set correctly
Expand Down
4 changes: 2 additions & 2 deletions textfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void fiftyoneDegreesTextFileIterateWithLimit(

// Shift the buffer to the left and load the next characters.
size_t shift = end - current;
memcpy(buffer, current, shift);
memmove(buffer, current, shift);
current = buffer + shift;
}
// Update end to the last line read
Expand Down Expand Up @@ -115,4 +115,4 @@ void fiftyoneDegreesTextFileIterate(
-1,
state,
callback);
}
}

0 comments on commit 52db864

Please sign in to comment.