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

Create cpp-linter.yml #2

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Create cpp-linter.yml #2

wants to merge 9 commits into from

Conversation

lejcik
Copy link
Owner

@lejcik lejcik commented Dec 2, 2021

Introduced C++ Linter analysis

@github-actions
Copy link

github-actions bot commented Dec 3, 2021

⚡ Static analysis result ⚡

🔴 Cppcheck found 48 issues! Click here to see details.

ScopeGuard(_Fun f)
: fnc_(std::move(f))
, active_(true)
{
}
~ScopeGuard()

!Line: 78 - style: Class 'ScopeGuard' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]

static_assert(sizeof(_T) < 0, "Unknown DBus type");
return "";
}
};
template <>

!Line: 71 - style: Checking if unsigned expression 'sizeof(_T)' is less than zero. [unsignedLessThanZero]

strv.push_back(const_cast<char*>(str.c_str()));
strv.push_back(nullptr);
return strv;
}
Connection::LoopExitEventFd::LoopExitEventFd()

!Line: 448 - style: Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]

void clearFlags();
std::string getInterfaceName() const;
std::string getMemberName() const;
std::string getSender() const;
std::string getPath() const;

!Line: 129 - style:inconclusive: Technically the member function 'sdbus::Message::clearFlags' can be const. [functionConst]

sdbus-cpp/src/Message.cpp

Lines 559 to 564 in 7f7825f

void Message::clearFlags()
{
ok_ = true;
}
void Message::copyTo(Message& destination, bool complete) const

!Line: 559 - note: Technically the member function 'sdbus::Message::clearFlags' can be const.

void clearFlags();
std::string getInterfaceName() const;
std::string getMemberName() const;
std::string getSender() const;
std::string getPath() const;

!Line: 129 - note: Technically the member function 'sdbus::Message::clearFlags' can be const.

Variant(const _ValueType& value)
: Variant()
{
msg_.openVariant(signature_of<_ValueType>::str());
msg_ << value;
msg_.closeVariant();

!Line: 59 - style: Class 'Variant' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]

ObjectPath(std::string path)
: std::string(std::move(path))
{}
using std::string::operator=;
};

!Line: 159 - style: Class 'ObjectPath' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]

Signature(std::string path)
: std::string(std::move(path))
{}
using std::string::operator=;
};

!Line: 178 - style: Class 'Signature' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]

sdbus-cpp/src/Message.cpp

Lines 798 to 803 in 7f7825f

return Slot{slot, [sdbus_ = sdbus_](void *slot){ sdbus_->sd_bus_slot_unref((sd_bus_slot*)slot); }};
}
MethodReply MethodCall::createReply() const
{
sd_bus_message* sdbusReply{};

!Line: 798 - warning: Redundant assignment of 'sdbus_' to itself. [selfAssignment]

Result(MethodCall call);
Result(const Result&) = delete;
Result& operator=(const Result&) = delete;
Result(Result&& other) = default;

!Line: 53 - style: Class 'Result' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]

sdbus-cpp/src/Object.h

Lines 112 to 117 in 7f7825f

InterfaceData(Object& object) : object(object) {}
using MethodName = std::string;
struct MethodData
{
const std::string inputArgs;

!Line: 112 - style: Struct 'InterfaceData' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]

sdbus-cpp/src/Object.cpp

Lines 143 to 148 in 7f7825f

void Object::setInterfaceFlags(const std::string& interfaceName, Flags flags)
{
auto& interface = getInterface(interfaceName);
interface.flags = flags;
}

!Line: 143 - performance: Function parameter 'flags' should be passed by const reference. [passedByValue]

sdbus-cpp/src/Object.cpp

Lines 365 to 370 in 7f7825f

auto& callback = interfaceData->properties[property].getCallback;
// Getter can be empty - the case of "write-only" property
if (!callback)
{
sd_bus_error_set(retError, "org.freedesktop.DBus.Error.Failed", "Cannot read property as it is write-only");
return 1;

!Line: 365 - style: Variable 'callback' can be declared with const [constVariable]

sdbus-cpp/src/Object.cpp

Lines 320 to 325 in 7f7825f

names += name + '\0';
return names;
}
int Object::sdbus_method_callback(sd_bus_message *sdbusMessage, void *userData, sd_bus_error *retError)
{

!Line: 320 - style: Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]

PendingAsyncCall(std::weak_ptr<void> callData);
private:
std::weak_ptr<void> callData_;
};

!Line: 335 - style: Class 'PendingAsyncCall' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]

sdbus-cpp/src/Proxy.h

Lines 150 to 155 in 7f7825f

auto callData = std::move(it->second);
calls_.erase(it);
lock.unlock();
// Releasing call slot pointer acquires global sd-bus mutex. We have to perform the release
// out of the `mutex_' critical section here, because if the `removeCall` is called by some

!Line: 150 - style: Variable 'callData' is assigned a value that is never used. [unreadVariable]

sdbus-cpp/src/Proxy.h

Lines 164 to 169 in 7f7825f

auto asyncCallSlots = std::move(calls_);
calls_ = {};
lock.unlock();
// Releasing call slot pointer acquires global sd-bus mutex. We have to perform the release
// out of the `mutex_' critical section here, because if the `clear` is called by some thread

!Line: 164 - style: Variable 'asyncCallSlots' is assigned a value that is never used. [unreadVariable]

sdbus-cpp/src/Types.cpp

Lines 47 to 52 in 7f7825f

void Variant::deserializeFrom(Message& msg)
{
msg.copyTo(msg_, false);
msg_.seal();
}

!Line: 47 - style: Parameter 'msg' can be declared with const [constParameter]

sdbus-cpp/src/SdBus.cpp

Lines 179 to 184 in 7f7825f

int SdBus::sd_bus_open_system_remote(sd_bus **ret, const char *host)
{
return ::sd_bus_open_system_remote(ret, host);
}
int SdBus::sd_bus_request_name(sd_bus *bus, const char *name, uint64_t flags)

!Line: 179 - style:inconclusive: Function 'sd_bus_open_system_remote' argument 2 names different: declaration 'hsot' definition 'host'. [funcArgNamesDifferent]

sdbus-cpp/src/SdBus.h

Lines 64 to 69 in 7f7825f

virtual int sd_bus_open_system_remote(sd_bus **ret, const char* hsot) override;
virtual int sd_bus_request_name(sd_bus *bus, const char *name, uint64_t flags) override;
virtual int sd_bus_release_name(sd_bus *bus, const char *name) override;
virtual int sd_bus_get_unique_name(sd_bus *bus, const char **name) override;
virtual int sd_bus_add_object_vtable(sd_bus *bus, sd_bus_slot **slot, const char *path, const char *interface, const sd_bus_vtable *vtable, void *userdata) override;
virtual int sd_bus_add_object_manager(sd_bus *bus, sd_bus_slot **slot, const char *path) override;

!Line: 64 - note: Function 'sd_bus_open_system_remote' argument 2 names different: declaration 'hsot' definition 'host'.

sdbus-cpp/src/SdBus.cpp

Lines 179 to 184 in 7f7825f

int SdBus::sd_bus_open_system_remote(sd_bus **ret, const char *host)
{
return ::sd_bus_open_system_remote(ret, host);
}
int SdBus::sd_bus_request_name(sd_bus *bus, const char *name, uint64_t flags)

!Line: 179 - note: Function 'sd_bus_open_system_remote' argument 2 names different: declaration 'hsot' definition 'host'.

sdbus-cpp/src/Proxy.cpp

Lines 299 to 304 in 7f7825f

void PendingAsyncCall::cancel()
{
if (auto ptr = callData_.lock(); ptr != nullptr)
{
auto* callData = static_cast<internal::Proxy::AsyncCalls::CallData*>(ptr.get());
callData->proxy.pendingAsyncCalls_.removeCall(callData->slot.get());

!Line: 299 - style: The function 'cancel' is never used. [unusedFunction]

sdbus-cpp/src/Object.cpp

Lines 426 to 431 in 7f7825f

std::unique_ptr<sdbus::IObject> createObject(sdbus::IConnection& connection, std::string objectPath)
{
auto* sdbusConnection = dynamic_cast<sdbus::internal::IConnection*>(&connection);
SDBUS_THROW_ERROR_IF(!sdbusConnection, "Connection is not a real sdbus-c++ connection", EINVAL);
return std::make_unique<sdbus::internal::Object>(*sdbusConnection, std::move(objectPath));

!Line: 426 - style: The function 'createObject' is never used. [unusedFunction]

sdbus-cpp/src/Proxy.cpp

Lines 322 to 327 in 7f7825f

std::unique_ptr<sdbus::IProxy> createProxy( IConnection& connection
, std::string destination
, std::string objectPath )
{
auto* sdbusConnection = dynamic_cast<sdbus::internal::IConnection*>(&connection);
SDBUS_THROW_ERROR_IF(!sdbusConnection, "Connection is not a real sdbus-c++ connection", EINVAL);

!Line: 322 - style: The function 'createProxy' is never used. [unusedFunction]

std::unique_ptr<sdbus::IConnection> createRemoteSystemBusConnection(const std::string& host)
{
auto interface = std::make_unique<sdbus::internal::SdBus>();
constexpr sdbus::internal::Connection::remote_system_bus_t remote_system_bus;
return std::make_unique<sdbus::internal::Connection>(std::move(interface), remote_system_bus, host);
}

!Line: 533 - style: The function 'createRemoteSystemBusConnection' is never used. [unusedFunction]

sdbus-cpp/src/Object.cpp

Lines 149 to 154 in 7f7825f

void Object::finishRegistration()
{
for (auto& item : interfaces_)
{
const auto& interfaceName = item.first;
auto& interfaceData = item.second;

!Line: 149 - style: The function 'finishRegistration' is never used. [unusedFunction]

sdbus-cpp/src/Object.cpp

Lines 224 to 229 in 7f7825f

sdbus::IConnection& Object::getConnection() const
{
return dynamic_cast<sdbus::IConnection&>(connection_);
}
const std::string& Object::getObjectPath() const

!Line: 224 - style: The function 'getConnection' is never used. [unusedFunction]

sdbus-cpp/src/Message.cpp

Lines 690 to 695 in 7f7825f

gid_t Message::getCredsEgid() const
{
uint64_t mask = SD_BUS_CREDS_EGID | SD_BUS_CREDS_AUGMENT;
sd_bus_creds *creds = nullptr;
SCOPE_EXIT{ sdbus_->sd_bus_creds_unref(creds); };
int r = sdbus_->sd_bus_query_sender_creds((sd_bus_message*)msg_, mask, &creds);

!Line: 690 - style: The function 'getCredsEgid' is never used. [unusedFunction]

sdbus-cpp/src/Message.cpp

Lines 662 to 667 in 7f7825f

uid_t Message::getCredsEuid() const
{
uint64_t mask = SD_BUS_CREDS_EUID | SD_BUS_CREDS_AUGMENT;
sd_bus_creds *creds = nullptr;
SCOPE_EXIT{ sdbus_->sd_bus_creds_unref(creds); };
int r = sdbus_->sd_bus_query_sender_creds((sd_bus_message*)msg_, mask, &creds);

!Line: 662 - style: The function 'getCredsEuid' is never used. [unusedFunction]

sdbus-cpp/src/Message.cpp

Lines 676 to 681 in 7f7825f

gid_t Message::getCredsGid() const
{
uint64_t mask = SD_BUS_CREDS_GID | SD_BUS_CREDS_AUGMENT;
sd_bus_creds *creds = nullptr;
SCOPE_EXIT{ sdbus_->sd_bus_creds_unref(creds); };
int r = sdbus_->sd_bus_query_sender_creds((sd_bus_message*)msg_, mask, &creds);

!Line: 676 - style: The function 'getCredsGid' is never used. [unusedFunction]

sdbus-cpp/src/Message.cpp

Lines 633 to 638 in 7f7825f

pid_t Message::getCredsPid() const
{
uint64_t mask = SD_BUS_CREDS_PID | SD_BUS_CREDS_AUGMENT;
sd_bus_creds *creds = nullptr;
SCOPE_EXIT{ sdbus_->sd_bus_creds_unref(creds); };

!Line: 633 - style: The function 'getCredsPid' is never used. [unusedFunction]

sdbus-cpp/src/Message.cpp

Lines 704 to 709 in 7f7825f

std::vector<gid_t> Message::getCredsSupplementaryGids() const
{
uint64_t mask = SD_BUS_CREDS_SUPPLEMENTARY_GIDS | SD_BUS_CREDS_AUGMENT;
sd_bus_creds *creds = nullptr;
SCOPE_EXIT{ sdbus_->sd_bus_creds_unref(creds); };
int r = sdbus_->sd_bus_query_sender_creds((sd_bus_message*)msg_, mask, &creds);

!Line: 704 - style: The function 'getCredsSupplementaryGids' is never used. [unusedFunction]

sdbus-cpp/src/Message.cpp

Lines 648 to 653 in 7f7825f

uid_t Message::getCredsUid() const
{
uint64_t mask = SD_BUS_CREDS_UID | SD_BUS_CREDS_AUGMENT;
sd_bus_creds *creds = nullptr;
SCOPE_EXIT{ sdbus_->sd_bus_creds_unref(creds); };
int r = sdbus_->sd_bus_query_sender_creds((sd_bus_message*)msg_, mask, &creds);

!Line: 648 - style: The function 'getCredsUid' is never used. [unusedFunction]

sdbus-cpp/src/Object.cpp

Lines 234 to 239 in 7f7825f

const Message* Object::getCurrentlyProcessedMessage() const
{
return m_CurrentlyProcessedMessage.load(std::memory_order_relaxed);
}
Object::InterfaceData& Object::getInterface(const std::string& interfaceName)

!Line: 234 - style: The function 'getCurrentlyProcessedMessage' is never used. [unusedFunction]

sdbus-cpp/src/Message.cpp

Lines 607 to 612 in 7f7825f

std::string Message::getDestination() const
{
auto destination = sd_bus_message_get_destination((sd_bus_message*)msg_);
return destination != nullptr ? destination : "";
}

!Line: 607 - style: The function 'getDestination' is never used. [unusedFunction]

sdbus-cpp/src/Message.cpp

Lines 584 to 589 in 7f7825f

std::string Message::getInterfaceName() const
{
auto interface = sd_bus_message_get_interface((sd_bus_message*)msg_);
return interface != nullptr ? interface : "";
}

!Line: 584 - style: The function 'getInterfaceName' is never used. [unusedFunction]

uint64_t Connection::getMethodCallTimeout() const
{
uint64_t timeout;
auto r = iface_->sd_bus_get_method_call_timeout(bus_.get(), &timeout);

!Line: 167 - style: The function 'getMethodCallTimeout' is never used. [unusedFunction]

sdbus-cpp/src/Object.cpp

Lines 229 to 234 in 7f7825f

const std::string& Object::getObjectPath() const
{
return objectPath_;
}
const Message* Object::getCurrentlyProcessedMessage() const

!Line: 229 - style: The function 'getObjectPath' is never used. [unusedFunction]

sdbus-cpp/src/Message.cpp

Lines 601 to 606 in 7f7825f

std::string Message::getPath() const
{
auto path = sd_bus_message_get_path((sd_bus_message*)msg_);
return path != nullptr ? path : "";
}

!Line: 601 - style: The function 'getPath' is never used. [unusedFunction]

sdbus-cpp/src/Message.cpp

Lines 726 to 731 in 7f7825f

std::string Message::getSELinuxContext() const
{
uint64_t mask = SD_BUS_CREDS_AUGMENT | SD_BUS_CREDS_SELINUX_CONTEXT;
sd_bus_creds *creds = nullptr;
SCOPE_EXIT{ sdbus_->sd_bus_creds_unref(creds); };
int r = sdbus_->sd_bus_query_sender_creds((sd_bus_message*)msg_, mask, &creds);

!Line: 726 - style: The function 'getSELinuxContext' is never used. [unusedFunction]

sdbus-cpp/src/Message.cpp

Lines 596 to 601 in 7f7825f

std::string Message::getSender() const
{
return sd_bus_message_get_sender((sd_bus_message*)msg_);
}
std::string Message::getPath() const

!Line: 596 - style: The function 'getSender' is never used. [unusedFunction]

std::string Connection::getUniqueName() const
{
const char* unique = nullptr;
auto r = iface_->sd_bus_get_unique_name(bus_.get(), &unique);
SDBUS_THROW_ERROR_IF(r < 0 || unique == nullptr, "Failed to get unique bus name", -r);
return unique;

!Line: 84 - style: The function 'getUniqueName' is never used. [unusedFunction]

sdbus-cpp/src/Object.cpp

Lines 219 to 224 in 7f7825f

bool Object::hasObjectManager() const
{
return objectManagerSlot_ != nullptr;
}
sdbus::IConnection& Object::getConnection() const

!Line: 219 - style: The function 'hasObjectManager' is never used. [unusedFunction]

sdbus-cpp/src/Proxy.cpp

Lines 313 to 318 in 7f7825f

bool PendingAsyncCall::isPending() const
{
return !callData_.expired();
}
}

!Line: 313 - style: The function 'isPending' is never used. [unusedFunction]

void Connection::releaseName(const std::string& name)
{
auto r = iface_->sd_bus_release_name(bus_.get(), name.c_str());
SDBUS_THROW_ERROR_IF(r < 0, "Failed to release bus name", -r);
}

!Line: 78 - style: The function 'releaseName' is never used. [unusedFunction]

sdbus-cpp/src/Message.cpp

Lines 835 to 840 in 7f7825f

void Signal::setDestination(const std::string& destination)
{
auto r = sdbus_->sd_bus_message_set_destination((sd_bus_message*)msg_, destination.c_str());
SDBUS_THROW_ERROR_IF(r < 0, "Failed to set signal destination", -r);
}

!Line: 835 - style: The function 'setDestination' is never used. [unusedFunction]

sdbus-cpp/src/Object.cpp

Lines 161 to 166 in 7f7825f

void Object::unregister()
{
interfaces_.clear();
removeObjectManager();
}

!Line: 161 - style: The function 'unregister' is never used. [unusedFunction]


🔴 clang-tidy found 8 issues! Click here to see details.

#include <sdbus-c++/IConnection.h>
#include <sdbus-c++/Message.h>
#include "IConnection.h"
#include "ScopeGuard.h"
#include "ISdBus.h"
#include <systemd/sd-bus.h>

!Line: 30 - error: 'sdbus-c++/IConnection.h' file not found [clang-diagnostic-error]

sdbus-cpp/src/Error.cpp

Lines 27 to 32 in 7f7825f

#include <sdbus-c++/Error.h>
#include <systemd/sd-bus.h>
#include "ScopeGuard.h"
namespace sdbus
{

!Line: 27 - error: 'sdbus-c++/Error.h' file not found [clang-diagnostic-error]

sdbus-cpp/src/Flags.cpp

Lines 27 to 32 in 7f7825f

#include <sdbus-c++/Flags.h>
#include <systemd/sd-bus.h>
namespace sdbus
{
uint64_t Flags::toSdBusInterfaceFlags() const

!Line: 27 - error: 'sdbus-c++/Flags.h' file not found [clang-diagnostic-error]

#include <sdbus-c++/Message.h>
#include <sdbus-c++/Types.h>
#include <sdbus-c++/Error.h>
#include "MessageUtils.h"
#include "ISdBus.h"
#include "IConnection.h"

!Line: 27 - error: 'sdbus-c++/Message.h' file not found [clang-diagnostic-error]

sdbus-cpp/src/Object.h

Lines 30 to 35 in 7f7825f

#include <sdbus-c++/IObject.h>
#include "IConnection.h"
#include <systemd/sd-bus.h>
#include <string>
#include <map>
#include <vector>

!Line: 30 - error: 'sdbus-c++/IObject.h' file not found [clang-diagnostic-error]

sdbus-cpp/src/Proxy.h

Lines 30 to 35 in 7f7825f

#include <sdbus-c++/IProxy.h>
#include "IConnection.h"
#include <systemd/sd-bus.h>
#include <string>
#include <memory>
#include <map>

!Line: 30 - error: 'sdbus-c++/IProxy.h' file not found [clang-diagnostic-error]

sdbus-cpp/src/SdBus.cpp

Lines 29 to 34 in 7f7825f

#include <sdbus-c++/Error.h>
namespace sdbus::internal {
sd_bus_message* SdBus::sd_bus_message_ref(sd_bus_message *m)
{

!Line: 29 - error: 'sdbus-c++/Error.h' file not found [clang-diagnostic-error]

sdbus-cpp/src/Types.cpp

Lines 27 to 32 in 7f7825f

#include <sdbus-c++/Types.h>
#include <sdbus-c++/Error.h>
#include "MessageUtils.h"
#include <systemd/sd-bus.h>
#include <cassert>

!Line: 27 - error: 'sdbus-c++/Types.h' file not found [clang-diagnostic-error]


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant