Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a cmake option to activate address sanitizers #146

Merged
merged 3 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: install boost
run: sudo apt-get install -y libboost-dev
- name: configure
run: mkdir build && cd build && cmake .. -DBUILDING_TESTS=1 -DINTEGRATION_TESTS=1
run: mkdir build && cd build && cmake .. -DBUILDING_TESTS=1 -DINTEGRATION_TESTS=1 -DWITH_ASAN=ON
env:
CXXFLAGS: -g -O2 -fprofile-arcs -ftest-coverage
CFLAGS: -g -O2 -fprofile-arcs -ftest-coverage
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()

option(WITH_ASAN "Compile with address sanitizer support" OFF)

##
## Check C++11 support / enable global pedantic and Wall
Expand Down Expand Up @@ -51,6 +52,10 @@ add_library(urcl SHARED
add_library(ur_client_library::urcl ALIAS urcl)
target_compile_options(urcl PRIVATE -Wall -Wextra -Wno-unused-parameter)
target_compile_options(urcl PUBLIC ${CXX17_FLAG})
if(WITH_ASAN)
target_compile_options(urcl PUBLIC -fsanitize=address)
target_link_options(urcl PUBLIC -fsanitize=address)
endif()
target_include_directories( urcl PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
Expand Down
2 changes: 1 addition & 1 deletion include/ur_client_library/comm/bin_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class BinParser
* \param buffer The buffer to copy the remaining bytes to.
* \param buffer_length Reference to write the number of remaining bytes to.
*/
void rawData(std::unique_ptr<uint8_t>& buffer, size_t& buffer_length)
void rawData(std::unique_ptr<uint8_t[]>& buffer, size_t& buffer_length)
{
buffer_length = buf_end_ - buf_pos_;
buffer.reset(new uint8_t[buffer_length]);
Expand Down
2 changes: 1 addition & 1 deletion include/ur_client_library/primary/primary_package.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class PrimaryPackage : public comm::URPackage<PackageHeader>
virtual std::string toString() const;

protected:
std::unique_ptr<uint8_t> buffer_;
std::unique_ptr<uint8_t[]> buffer_;
size_t buffer_length_;
};

Expand Down
2 changes: 1 addition & 1 deletion include/ur_client_library/rtde/rtde_package.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class RTDEPackage : public comm::URPackage<PackageHeader>
virtual std::string toString() const;

protected:
std::unique_ptr<uint8_t> buffer_;
std::unique_ptr<uint8_t[]> buffer_;
size_t buffer_length_;
PackageType type_;
};
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bin_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ TEST(bin_parser, raw_data_parser)
0x62, 0x65, 0x20, 0x70, 0x61, 0x72, 0x73, 0x65, 0x64 };
comm::BinParser bp(buffer, sizeof(buffer));

std::unique_ptr<uint8_t> raw_data;
std::unique_ptr<uint8_t[]> raw_data;
size_t size;
bp.rawData(raw_data, size);

Expand Down
8 changes: 4 additions & 4 deletions tests/test_tcp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <gtest/gtest.h>
#include <condition_variable>
#include <chrono>
#include <memory>

#include <ur_client_library/comm/tcp_server.h>
#include <ur_client_library/comm/tcp_socket.h>
Expand Down Expand Up @@ -225,13 +226,12 @@ TEST_F(TCPServerTest, unlimited_clients_allowed)
server.start();

// Test that a large number of clients can connect to the server
std::vector<Client*> clients;
Client* client;
std::vector<std::unique_ptr<Client>> clients;
std::unique_ptr<Client> client;
for (unsigned int i = 0; i < 100; ++i)
{
client = new Client(port_);
clients.push_back(std::make_unique<Client>(port_));
ASSERT_TRUE(waitForConnectionCallback());
clients.push_back(client);
}
}

Expand Down