Skip to content

Commit

Permalink
Fix cppcheck warnings, use stricter code quality rules
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Dec 30, 2024
1 parent d5d11d7 commit a91c481
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cpp/base/device_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DeviceFactory
shared_ptr<PrimaryDevice> CreateDevice(PbDeviceType, int, const string&) const;
PbDeviceType GetTypeForFile(const string&) const;

auto GetExtensionMapping() const
const auto& GetExtensionMapping() const
{
return mapping;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/base/property_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ property_map PropertyHandler::GetProperties(const string &filter) const
return filtered_properties;
}

property_map PropertyHandler::GetUnknownProperties() const
const property_map& PropertyHandler::GetUnknownProperties() const
{
return unknown_properties;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/base/property_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class PropertyHandler
void Init(const string&, const property_map&, bool);

property_map GetProperties(const string& = "") const;
property_map GetUnknownProperties() const;
const property_map& GetUnknownProperties() const;
const string& RemoveProperty(const string&, const string& = "");
void AddProperty(const string&, string_view);
void RemoveProperties(const string&);
Expand Down
2 changes: 1 addition & 1 deletion cpp/command/command_image_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CommandImageSupport
{
return depth;
}
string GetDefaultFolder() const
const string& GetDefaultFolder() const
{
return default_folder;
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/devices/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void Disk::Write(AccessMode mode)
void Disk::Verify(AccessMode mode)
{
// A transfer length of 0 is legal
const auto& [_, start, count] = CheckAndGetStartAndCount(mode);
const auto& [valid, start, count] = CheckAndGetStartAndCount(mode);

// Flush the cache according to the specification
FlushCache();
Expand Down Expand Up @@ -431,7 +431,7 @@ int Disk::WriteData(cdb_t cdb, data_out_t buf, int, int l)

void Disk::Seek(AccessMode mode)
{
const auto& [valid, _, __] = CheckAndGetStartAndCount(mode);
const auto& [valid, start, count] = CheckAndGetStartAndCount(mode);
if (valid) {
CheckReady();
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/scsi_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ScsiGeneric : public PrimaryDevice
return device + " (" + GetPaddedName() + ")";
}

string GetDevice() const
const string& GetDevice() const
{
return device;
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/devices/storage_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class StorageDevice : public PrimaryDevice
{
filename = filesystem::path(file);
}
string GetLastFilename() const
const string& GetLastFilename() const
{
return last_filename;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ class StorageDevice : public PrimaryDevice
medium_changed = b;
}

static auto GetReservedFiles()
static const auto& GetReservedFiles()
{
return reserved_files;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/tap_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pair<string, string> TapDriver::ExtractAddressAndMask(logger &logger) const
address = components[0];

const int m = ParseAsUnsignedInt(components[1]);
if (m == -1 || m < 8 || m > 32) {
if (m < 8 || m > 32) {
logger.error("Invalid CIDR netmask notation '{}'", components[1]);
return {"", ""};
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/devices/tape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ bool Tape::Locate(bool locate_16)
throw ScsiException(SenseKey::ILLEGAL_REQUEST, Asc::INVALID_FIELD_IN_CDB);
}

auto identifier = static_cast<uint32_t>(locate_16 ? GetCdbInt64(4) : GetCdbInt32(3));
auto identifier = locate_16 ? GetCdbInt64(4) : GetCdbInt32(3);
const bool bt = GetCdbByte(1) & 0x04;

if (tar_file) {
Expand All @@ -561,7 +561,7 @@ bool Tape::Locate(bool locate_16)
} else {
ResetPositions();
if (identifier) {
return FindObject(identifier);
return FindObject(static_cast<int>(identifier));
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions cpp/s2pexec/s2pexec_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,7 @@ bool S2pExec::ParseArguments(span<char*> args, bool in_process)
if (buffer_size = ParseAsUnsignedInt(buf); buffer_size <= 0) {
throw ParserException("Invalid receive buffer size: '" + buf + "'");
}
else {
buffer.resize(buffer_size);
}
buffer.resize(buffer_size);
}

return true;
Expand Down
10 changes: 4 additions & 6 deletions cpp/shared/s2p_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,10 @@ string s2p_util::ParseIdAndLun(const string &id_spec, int &id, int &lun)
}

if (const auto &components = Split(id_spec, COMPONENT_SEPARATOR, 2); !components.empty()) {
if (components.size() >= 1) {
id = ParseAsUnsignedInt(components[0]);
if (id == -1 || id > 7) {
id = -1;
return "Invalid device ID: '" + components[0] + "' (0-7)";
}
id = ParseAsUnsignedInt(components[0]);
if (id == -1 || id > 7) {
id = -1;
return "Invalid device ID: '" + components[0] + "' (0-7)";
}

if (components.size() >= 2) {
Expand Down
6 changes: 2 additions & 4 deletions cpp/test/primary_device_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,8 @@ TEST(PrimaryDeviceTest, ReportLuns)

TEST(PrimaryDeviceTest, Dispatch)
{
auto [__, device] = CreatePrimaryDevice();

Dispatch(device, static_cast<ScsiCommand>(0x1f), SenseKey::ILLEGAL_REQUEST, Asc::INVALID_COMMAND_OPERATION_CODE,
"Unsupported SCSI command");
Dispatch(make_shared<MockPrimaryDevice>(0), static_cast<ScsiCommand>(0x1f), SenseKey::ILLEGAL_REQUEST,
Asc::INVALID_COMMAND_OPERATION_CODE, "Unsupported SCSI command");
}

TEST(PrimaryDeviceTest, Init)
Expand Down
4 changes: 2 additions & 2 deletions cpp/test/tape_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ TEST(TapeTest, Erase6_simh)

TEST(TapeTest, Erase6_tar)
{
auto [__, tape] = CreateTape();
auto [controller, tape] = CreateTape();
CreateImageFile(*tape, 512, "tar");

Dispatch(tape, ScsiCommand::ERASE_6, SenseKey::ILLEGAL_REQUEST,
Expand Down Expand Up @@ -765,7 +765,7 @@ TEST(TapeTest, Space6_simh)

TEST(TapeTest, Space6_tar)
{
auto [___, tape] = CreateTape();
auto [controller, tape] = CreateTape();
CreateImageFile(*tape, 512, "tar");

Dispatch(tape, ScsiCommand::SPACE_6, SenseKey::ILLEGAL_REQUEST,
Expand Down

0 comments on commit a91c481

Please sign in to comment.