From 8542fa62c13306e8e8cc623183f105a868a36b6c Mon Sep 17 00:00:00 2001 From: Przemyslaw Czarnowski Date: Wed, 26 Jan 2022 16:51:08 +0100 Subject: Add -Wextra, remove warnings (#1) Removed all -Wextra warnings in VM sources. -Wno-unused-parameter has to be disabled due to lots of such warnings in sdbusplus. Tested: Compilation generates no warnings Signed-off-by: Przemyslaw Czarnowski --- CMakeLists.txt | 4 +++- src/events.hpp | 4 +--- src/state/activating_state.cpp | 19 ++++++++++--------- src/state/active_state.hpp | 8 +++++--- src/state/initial_state.hpp | 37 +++++++++++++++++++++++-------------- src/state/ready_state.hpp | 10 +++++++++- src/state_machine.hpp | 2 +- 7 files changed, 52 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e9eb2a4..97778d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,9 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-rtti") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fno-rtti") +# Silence sdbusplus warnings +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os -flto") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") diff --git a/src/events.hpp b/src/events.hpp index 7a6adde..320d344 100644 --- a/src/events.hpp +++ b/src/events.hpp @@ -22,14 +22,12 @@ struct RegisterDbusEvent : public BasicEvent std::shared_ptr bus, std::shared_ptr objServer) : BasicEvent(__FUNCTION__), - bus(bus), objServer(objServer), - emitMountEvent(std::move(emitMountEvent)) + bus(bus), objServer(objServer) { } std::shared_ptr bus; std::shared_ptr objServer; - std::function emitMountEvent; }; struct MountEvent : public BasicEvent diff --git a/src/state/activating_state.cpp b/src/state/activating_state.cpp index 7506aed..686de99 100644 --- a/src/state/activating_state.cpp +++ b/src/state/activating_state.cpp @@ -48,8 +48,8 @@ std::unique_ptr std::move(gadget), event); } -std::unique_ptr - ActivatingState::handleEvent(SubprocessStoppedEvent event) +std::unique_ptr ActivatingState::handleEvent([ + [maybe_unused]] SubprocessStoppedEvent event) { LogMsg(Logger::Error, "Process ended prematurely"); return std::make_unique(machine); @@ -229,7 +229,7 @@ std::unique_ptr args.insert(args.end(), params.begin(), params.end()); if (!process->spawn(args, [&machine = machine, secret = std::move(secret)]( - int exitCode, bool isReady) { + int exitCode, [[maybe_unused]] bool isReady) { LogMsg(Logger::Info, machine.getName(), " process ended."); machine.getExitCode() = exitCode; machine.emitSubprocessStoppedEvent(); @@ -278,11 +278,12 @@ std::unique_ptr { // Pack password into buffer utils::CredentialsProvider::SecureBuffer buff = - machine.getTarget()->credentials->pack([](const std::string& user, - const std::string& pass, - std::vector& buff) { - std::copy(pass.begin(), pass.end(), std::back_inserter(buff)); - }); + machine.getTarget()->credentials->pack( + []([[maybe_unused]] const std::string& user, + const std::string& pass, std::vector& buff) { + std::copy(pass.begin(), pass.end(), + std::back_inserter(buff)); + }); // Prepare file to provide the password with secret = std::make_unique(std::move(buff)); @@ -319,7 +320,7 @@ bool ActivatingState::getImagePathFromUrl(const std::string& urlScheme, } else { - LogMsg(Logger::Error, "Provied url does not match scheme"); + LogMsg(Logger::Error, "Provided url does not match scheme"); return false; } } diff --git a/src/state/active_state.hpp b/src/state/active_state.hpp index a2a8653..a204dc3 100644 --- a/src/state/active_state.hpp +++ b/src/state/active_state.hpp @@ -45,7 +45,8 @@ struct ActiveState : public BasicStateT // unmount media & stop retriggering timer boost::asio::spawn( machine.getIoc(), - [&machine = machine](boost::asio::yield_context yield) { + [&machine = machine]( + [[maybe_unused]] boost::asio::yield_context yield) { machine.emitUnmountEvent(); }); return; @@ -77,7 +78,7 @@ struct ActiveState : public BasicStateT machine, std::move(process), std::move(gadget), std::move(event)); } - std::unique_ptr handleEvent(UnmountEvent event) + std::unique_ptr handleEvent([[maybe_unused]] UnmountEvent event) { return std::make_unique(machine, std::move(process), std::move(gadget)); @@ -86,7 +87,8 @@ struct ActiveState : public BasicStateT [[noreturn]] std::unique_ptr handleEvent(MountEvent event) { LogMsg(Logger::Error, "InvalidĀ event: ", event.eventName); - throw sdbusplus::exception::SdBusError(EPERM, "Operation not permitted in active state"); + throw sdbusplus::exception::SdBusError( + EPERM, "Operation not permitted in active state"); } template diff --git a/src/state/initial_state.hpp b/src/state/initial_state.hpp index 02fe479..0529d9f 100644 --- a/src/state/initial_state.hpp +++ b/src/state/initial_state.hpp @@ -2,6 +2,8 @@ #include "basic_state.hpp" #include "ready_state.hpp" +#include + struct InitialState : public BasicStateT { static std::string_view stateName() @@ -70,14 +72,15 @@ struct InitialState : public BasicStateT processIface->register_property( "Active", bool(false), - [](const bool& req, bool& property) { return 0; }, - [&machine = machine](const bool& property) -> bool { - return machine.getState().get_if(); - }); + []([[maybe_unused]] const bool& req, + [[maybe_unused]] bool& property) { return 0; }, + [&machine = machine]([[maybe_unused]] const bool& property) + -> bool { return machine.getState().get_if(); }); processIface->register_property( "ExitCode", int32_t(0), - [](const int32_t& req, int32_t& property) { return 0; }, - [&machine = machine](const int32_t& property) { + []([[maybe_unused]] const int32_t& req, + [[maybe_unused]] int32_t& property) { return 0; }, + [&machine = machine]([[maybe_unused]] const int32_t& property) { return machine.getExitCode(); }); processIface->initialize(); @@ -137,12 +140,14 @@ struct InitialState : public BasicStateT iface->register_property("Socket", machine.getConfig().unixSocket); iface->register_property( "ImageURL", std::string(), - [](const std::string& req, std::string& property) { + []([[maybe_unused]] const std::string& req, + [[maybe_unused]] std::string& property) { throw sdbusplus::exception::SdBusError( EPERM, "Setting ImageURL property is not allowed"); return -1; }, - [&target = machine.getTarget()](const std::string& property) { + [&target = machine.getTarget()]( + [[maybe_unused]] const std::string& property) { if (target) { return target->imgUrl; @@ -151,8 +156,10 @@ struct InitialState : public BasicStateT }); iface->register_property( "WriteProtected", bool(true), - [](const bool& req, bool& property) { return 0; }, - [&target = machine.getTarget()](const bool& property) { + []([[maybe_unused]] const bool& req, + [[maybe_unused]] bool& property) { return 0; }, + [&target = + machine.getTarget()]([[maybe_unused]] const bool& property) { if (target) { return !target->rw; @@ -164,13 +171,15 @@ struct InitialState : public BasicStateT Configuration::MountPoint::defaultTimeout)); iface->register_property( "RemainingInactivityTimeout", 0, - [](const int& req, int& property) { + []([[maybe_unused]] const int& req, + [[maybe_unused]] int& property) { throw sdbusplus::exception::SdBusError( EPERM, "Setting RemainingInactivityTimeout property is " "not allowed"); return -1; }, - [&config = machine.getConfig()](const int& property) -> int { + [&config = machine.getConfig()]( + [[maybe_unused]] const int& property) -> int { return config.remainingInactivityTimeout.count(); }); iface->initialize(); @@ -280,8 +289,8 @@ struct InitialState : public BasicStateT LogMsg(Logger::Info, "[App]: Mount called on ", getObjectPath(machine), machine.getName()); - interfaces::MountPointStateMachine::Target target = {imgUrl, - rw}; + interfaces::MountPointStateMachine::Target target = { + imgUrl, rw, nullptr, nullptr}; if (std::holds_alternative(fd)) { diff --git a/src/state/ready_state.hpp b/src/state/ready_state.hpp index 2243143..bf1e160 100644 --- a/src/state/ready_state.hpp +++ b/src/state/ready_state.hpp @@ -2,6 +2,13 @@ #include "activating_state.hpp" #include "basic_state.hpp" +#include "logger.hpp" + +#include +#include +#include +#include +#include struct ReadyState : public BasicStateT { @@ -50,7 +57,8 @@ struct ReadyState : public BasicStateT [[noreturn]] std::unique_ptr handleEvent(UnmountEvent event) { LogMsg(Logger::Error, "InvalidĀ event: ", event.eventName); - throw sdbusplus::exception::SdBusError(EPERM, "Operation not permitted in ready state"); + throw sdbusplus::exception::SdBusError( + EPERM, "Operation not permitted in ready state"); } template diff --git a/src/state_machine.hpp b/src/state_machine.hpp index 3e525cf..259802c 100644 --- a/src/state_machine.hpp +++ b/src/state_machine.hpp @@ -53,7 +53,7 @@ struct MountPointStateMachine : public interfaces::MountPointStateMachine { state = std::move(newState); LogMsg(Logger::Info, name, " state changed to ", state->getStateName()); - if (newState = state->onEnter()) + if ((newState = state->onEnter())) { changeState(std::move(newState)); } -- cgit v1.2.3