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

Change workflow for cppcheck and clang-format #210

Merged
merged 7 commits into from
Feb 2, 2024
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
14 changes: 12 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:

jobs:
pre-commit:
clang-tidy:
runs-on: ubuntu-latest
container: egecetinn/ubuntu2204
steps:
Expand All @@ -16,12 +16,22 @@ jobs:
submodules: recursive
- name: Prepare
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- uses: pre-commit/[email protected]
- name: Configure
run: cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -S . -B build
- name: Clang-tidy
run: run-clang-tidy -j`nproc` -p=build -header-filter=`pwd`/include/ src/*.cpp src/**/*.cpp

format:
runs-on: ubuntu-latest
container: egecetinn/alpine
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Run clang-format
run: clang-format include/*.hpp include/**/*.hpp src/*.cpp src/**/*.cpp --verbose --dry-run --Werror
- name: Run cppcheck
run: cppcheck -Iinclude/ src --verbose --enable=all --error-exitcode=1 --std=c++14 --language=c++ --suppressions-list=cppcheckSuppressions.txt --inline-suppr

coverage:
runs-on: ubuntu-latest
container: egecetinn/ubuntu2204
Expand Down
6 changes: 0 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ repos:
rev: 23.12.1
hooks:
- id: black
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-format
- id: cppcheck
args: ["--std=c++14", "--language=c++", "--suppressions-list=cppcheckSuppressions.txt", "--inline-suppr"]
- repo: https://github.com/cmake-lint/cmake-lint
rev: 1.4.2
hooks:
Expand Down
6 changes: 3 additions & 3 deletions cppcheckSuppressions.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*:thirdparty/*
*:tests/*
missingInclude:*
unusedStructMember:*
missingIncludeSystem:*
unmatchedSuppression:*
unusedFunction:*
2 changes: 1 addition & 1 deletion include/connection/Zeromq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class ZeroMQ {
private:
// Internal context
std::shared_ptr<zmq::context_t> contextPtr;
std::shared_ptr<zmq::context_t> contextPtr{std::make_shared<zmq::context_t>(1)};
// Internal socket
std::unique_ptr<zmq::socket_t> socketPtr;

Expand Down
4 changes: 2 additions & 2 deletions src/connection/Http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
void HTTP::setCommonFields(const std::string &fullURL, std::string &receivedData, CURLoption method)
{
curl_easy_setopt(curl, CURLOPT_URL, fullURL.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&receivedData); // Register user-supplied memory
curl_easy_setopt(curl, CURLOPT_WRITEDATA, static_cast<void *>(&receivedData)); // Register user-supplied memory
curl_easy_setopt(curl, method, 1L);
}

Expand All @@ -16,7 +16,7 @@ void HTTP::setCommonFields(const std::string &fullURL, std::string &receivedData
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload.c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, payload.size());
curl_easy_setopt(curl, CURLOPT_URL, fullURL.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&receivedData); // Register user-supplied memory
curl_easy_setopt(curl, CURLOPT_WRITEDATA, static_cast<void *>(&receivedData)); // Register user-supplied memory
curl_easy_setopt(curl, method, 1L);
}

Expand Down
6 changes: 3 additions & 3 deletions src/connection/RawSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void RawSocket::init(int domain, int type, int protocol, sockaddr_ll &_addr)
RawSocket::RawSocket(std::string iface, bool isWrite) : writeMode(isWrite), iFace(std::move(iface))
{
// Prepare socket address
memset((void *)&addr, 0, sizeof(sockaddr_ll));
memset(static_cast<void *>(&addr), 0, sizeof(sockaddr_ll));
addr.sll_family = AF_PACKET;
addr.sll_protocol = htons(ETH_P_ALL);
addr.sll_ifindex = static_cast<int>(if_nametoindex(iFace.c_str()));
Expand All @@ -39,14 +39,14 @@ RawSocket::RawSocket(std::string iface, bool isWrite) : writeMode(isWrite), iFac

// Interface request
ifreq ifr{};
memset((void *)&ifr, 0, sizeof(ifreq));
memset(static_cast<void *>(&ifr), 0, sizeof(ifreq));
memcpy(std::addressof(ifr.ifr_name), iFace.c_str(),
iFace.size()); // Size should be sufficient because if_nametoindex not failed

if (isWrite)
{
init(PF_PACKET, SOCK_RAW, IPPROTO_RAW, addr);
if (setsockopt(sockFd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) < 0)
if (setsockopt(sockFd, SOL_SOCKET, SO_BINDTODEVICE, static_cast<void *>(&ifr), sizeof(ifr)) < 0)
{
throw std::runtime_error(std::string("Can't set socket options: ") + getErrnoString(errno));
}
Expand Down
1 change: 0 additions & 1 deletion src/connection/Zeromq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ void ZeroMQ::init(const std::shared_ptr<zmq::context_t> &ctx, const zmq::socket_

ZeroMQ::ZeroMQ(const zmq::socket_type &type, const std::string &addr, bool isBind)
{
contextPtr = std::make_shared<zmq::context_t>(1);
init(contextPtr, type, addr, isBind);
}

Expand Down
4 changes: 1 addition & 3 deletions src/metrics/PrometheusServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
#include <limits>

PrometheusServer::PrometheusServer(const std::string &serverAddr)
: mainExposer(std::make_unique<prometheus::Exposer>(serverAddr, 1))
{
// Init service
mainExposer = std::make_unique<prometheus::Exposer>(serverAddr, 1);

auto reg = std::make_shared<prometheus::Registry>();

// Basic information
Expand Down
4 changes: 2 additions & 2 deletions src/telnet/TelnetServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ bool TelnetSession::processCommandHistory(std::string &buffer)
{
if (m_historyCursor != m_history.begin())
{
m_historyCursor--;
--m_historyCursor;
}
buffer = *m_historyCursor;

Expand All @@ -392,7 +392,7 @@ bool TelnetSession::processCommandHistory(std::string &buffer)
{
if (next(m_historyCursor) != m_history.end())
{
m_historyCursor++;
++m_historyCursor;
}
buffer = *m_historyCursor;

Expand Down
Loading