Fix CircleCI build, more coverity fixes.

This commit is contained in:
2023-10-19 22:57:55 -07:00
parent a5bb31943c
commit 2a23d2e204
9 changed files with 42 additions and 24 deletions

View File

@@ -207,7 +207,13 @@ Buffer::Resize(size_t newCapacity)
auto newContents = new uint8_t[newCapacity];
memset(newContents, 0, newCapacity);
if (this->length > 0) {
// Defensive coding check.
if ((this->length > 0) && (this->contents == nullptr)) {
abort();
}
if (this->length > 0 && this->contents != nullptr) {
memcpy(newContents, this->contents, this->length);
}

View File

@@ -21,11 +21,12 @@
///
#include <cassert>
#include <iostream>
#include <regex>
#include <utility>
#include <vector>
#include <vector>
#include <scsl/Flags.h>
#include <scsl/StringUtil.h>
@@ -76,14 +77,14 @@ Flags::Flags(std::string fName)
Flags::Flags(std::string fName, std::string fDescription)
: name(fName), description(fDescription)
: name(std::move(fName)), description(std::move(fDescription))
{
}
Flags::~Flags()
{
for (auto flag : this->flags) {
for (auto &flag : this->flags) {
if (flag.second->Type == FlagType::String) {
delete flag.second->Value.s;
}
@@ -103,7 +104,8 @@ Flags::Register(std::string fName, FlagType fType, std::string fDescription)
return false;
}
auto flag = NewFlag(fName, fType, fDescription);
auto flag = NewFlag(fName, fType, std::move(fDescription));
assert(flag != nullptr);
this->flags[fName] = flag;
return true;
}
@@ -124,7 +126,7 @@ Flags::Register(std::string fName, bool defaultValue, std::string fDescription)
bool
Flags::Register(std::string fName, int defaultValue, std::string fDescription)
{
if (!this->Register(fName, FlagType::Integer, fDescription)) {
if (!this->Register(fName, FlagType::Integer, std::move(fDescription))) {
return false;
}
@@ -139,6 +141,8 @@ Flags::Register(std::string fName, unsigned int defaultValue, std::string fDescr
if (!this->Register(fName, FlagType::UnsignedInteger, std::move(fDescription))) {
return false;
}
assert(this->flags.count(fName) != 0);
assert(this->flags[fName] != nullptr);
this->flags[fName]->Value.u = defaultValue;
return true;
@@ -164,7 +168,7 @@ Flags::Register(std::string fName, std::string defaultValue, std::string fDescri
return false;
}
this->flags[fName]->Value.s = new std::string(defaultValue);
this->flags[fName]->Value.s = new std::string(std::move(defaultValue));
return true;
}
@@ -368,7 +372,7 @@ Flags::Arg(size_t i)
Flag *
Flags::checkGetArg(std::string fName, FlagType eType)
Flags::checkGetArg(std::string& fName, FlagType eType)
{
if (this->flags[fName] == 0) {
return nullptr;

View File

@@ -62,7 +62,7 @@ SplitKeyValuePair(std::string line, char delimiter)
std::string sDelim;
sDelim.push_back(std::move(delimiter));
return SplitKeyValuePair(line, sDelim);
return SplitKeyValuePair(std::move(line), sDelim);
}
@@ -154,7 +154,7 @@ WrapText(std::string& line, size_t lineLength)
}
std::string wLine;
for (auto word: parts) {
for (auto &word: parts) {
if (word.size() == 0) {
continue;
}

View File

@@ -53,7 +53,7 @@ SimpleSuite::Silence()
void
SimpleSuite::AddTest(std::string name, std::function<bool()> test)
{
UnitTest const test_case = {name, test};
const UnitTest test_case = {std::move(name), test};
tests.push_back(test_case);
}
@@ -62,7 +62,7 @@ void
SimpleSuite::AddFailingTest(std::string name, std::function<bool()> test)
{
// auto ntest = [&test]() { return !test(); };
UnitTest test_case = {name, [&test]() { return !test(); }};
const UnitTest test_case = {std::move(name), [&test]() { return !test(); }};
tests.push_back(test_case);
}