Fix CircleCI build, more coverity fixes.
This commit is contained in:
parent
a5bb31943c
commit
2a23d2e204
|
@ -33,4 +33,3 @@ workflows:
|
||||||
ctest:
|
ctest:
|
||||||
jobs:
|
jobs:
|
||||||
- ctest
|
- ctest
|
||||||
- static_analysis
|
|
||||||
|
|
14
.clang-tidy
14
.clang-tidy
|
@ -12,6 +12,7 @@ Checks: >-
|
||||||
-cppcoreguidelines-avoid-magic-numbers,
|
-cppcoreguidelines-avoid-magic-numbers,
|
||||||
-cppcoreguidelines-avoid-non-const-global-variables,
|
-cppcoreguidelines-avoid-non-const-global-variables,
|
||||||
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
|
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
|
||||||
|
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
||||||
-cppcoreguidelines-pro-type-vararg,
|
-cppcoreguidelines-pro-type-vararg,
|
||||||
-google-readability-braces-around-statements,
|
-google-readability-braces-around-statements,
|
||||||
-google-readability-function-size,
|
-google-readability-function-size,
|
||||||
|
@ -20,14 +21,9 @@ Checks: >-
|
||||||
-modernize-use-nodiscard,
|
-modernize-use-nodiscard,
|
||||||
-modernize-use-trailing-return-type,
|
-modernize-use-trailing-return-type,
|
||||||
-performance-unnecessary-value-param,
|
-performance-unnecessary-value-param,
|
||||||
-readability-magic-numbers,
|
-readability-magic-numbers
|
||||||
|
|
||||||
CheckOptions:
|
CheckOptions:
|
||||||
- key: readability-function-cognitive-complexity.Threshold
|
readability-function-cognitive-complexity.Threshold: 100
|
||||||
value: 100
|
readability-function-cognitive-complexity.IgnoreMacros: true
|
||||||
- key: readability-function-cognitive-complexity.IgnoreMacros
|
readability-identifier-naming.ClassCase: CamelCase
|
||||||
value: true
|
|
||||||
# Set naming conventions for your style below (there are dozens of naming settings possible):
|
|
||||||
# See https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html
|
|
||||||
- key: readability-identifier-naming.ClassCase
|
|
||||||
value: CamelCase
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ project(scsl LANGUAGES CXX
|
||||||
set(CMAKE_CXX_STANDARD 14)
|
set(CMAKE_CXX_STANDARD 14)
|
||||||
set(CMAKE_VERBOSE_MAKEFILES TRUE)
|
set(CMAKE_VERBOSE_MAKEFILES TRUE)
|
||||||
set(VERBOSE YES)
|
set(VERBOSE YES)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
# compile options:
|
# compile options:
|
||||||
# -Wall Default to all errors.
|
# -Wall Default to all errors.
|
||||||
|
|
|
@ -329,7 +329,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ParseStatus parseArg(int argc, char **argv, int &index);
|
ParseStatus parseArg(int argc, char **argv, int &index);
|
||||||
Flag *checkGetArg(std::string fName, FlagType eType);
|
Flag *checkGetArg(std::string& fName, FlagType eType);
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string description;
|
std::string description;
|
||||||
|
|
|
@ -207,7 +207,13 @@ Buffer::Resize(size_t newCapacity)
|
||||||
auto newContents = new uint8_t[newCapacity];
|
auto newContents = new uint8_t[newCapacity];
|
||||||
|
|
||||||
memset(newContents, 0, 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);
|
memcpy(newContents, this->contents, this->length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,12 @@
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
#include <scsl/Flags.h>
|
#include <scsl/Flags.h>
|
||||||
#include <scsl/StringUtil.h>
|
#include <scsl/StringUtil.h>
|
||||||
|
|
||||||
|
@ -76,14 +77,14 @@ Flags::Flags(std::string fName)
|
||||||
|
|
||||||
|
|
||||||
Flags::Flags(std::string fName, std::string fDescription)
|
Flags::Flags(std::string fName, std::string fDescription)
|
||||||
: name(fName), description(fDescription)
|
: name(std::move(fName)), description(std::move(fDescription))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Flags::~Flags()
|
Flags::~Flags()
|
||||||
{
|
{
|
||||||
for (auto flag : this->flags) {
|
for (auto &flag : this->flags) {
|
||||||
if (flag.second->Type == FlagType::String) {
|
if (flag.second->Type == FlagType::String) {
|
||||||
delete flag.second->Value.s;
|
delete flag.second->Value.s;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +104,8 @@ Flags::Register(std::string fName, FlagType fType, std::string fDescription)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto flag = NewFlag(fName, fType, fDescription);
|
auto flag = NewFlag(fName, fType, std::move(fDescription));
|
||||||
|
assert(flag != nullptr);
|
||||||
this->flags[fName] = flag;
|
this->flags[fName] = flag;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +126,7 @@ Flags::Register(std::string fName, bool defaultValue, std::string fDescription)
|
||||||
bool
|
bool
|
||||||
Flags::Register(std::string fName, int defaultValue, std::string fDescription)
|
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;
|
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))) {
|
if (!this->Register(fName, FlagType::UnsignedInteger, std::move(fDescription))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
assert(this->flags.count(fName) != 0);
|
||||||
|
assert(this->flags[fName] != nullptr);
|
||||||
|
|
||||||
this->flags[fName]->Value.u = defaultValue;
|
this->flags[fName]->Value.u = defaultValue;
|
||||||
return true;
|
return true;
|
||||||
|
@ -164,7 +168,7 @@ Flags::Register(std::string fName, std::string defaultValue, std::string fDescri
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->flags[fName]->Value.s = new std::string(defaultValue);
|
this->flags[fName]->Value.s = new std::string(std::move(defaultValue));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,7 +372,7 @@ Flags::Arg(size_t i)
|
||||||
|
|
||||||
|
|
||||||
Flag *
|
Flag *
|
||||||
Flags::checkGetArg(std::string fName, FlagType eType)
|
Flags::checkGetArg(std::string& fName, FlagType eType)
|
||||||
{
|
{
|
||||||
if (this->flags[fName] == 0) {
|
if (this->flags[fName] == 0) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -62,7 +62,7 @@ SplitKeyValuePair(std::string line, char delimiter)
|
||||||
std::string sDelim;
|
std::string sDelim;
|
||||||
|
|
||||||
sDelim.push_back(std::move(delimiter));
|
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;
|
std::string wLine;
|
||||||
for (auto word: parts) {
|
for (auto &word: parts) {
|
||||||
if (word.size() == 0) {
|
if (word.size() == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ SimpleSuite::Silence()
|
||||||
void
|
void
|
||||||
SimpleSuite::AddTest(std::string name, std::function<bool()> test)
|
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);
|
tests.push_back(test_case);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ void
|
||||||
SimpleSuite::AddFailingTest(std::string name, std::function<bool()> test)
|
SimpleSuite::AddFailingTest(std::string name, std::function<bool()> test)
|
||||||
{
|
{
|
||||||
// auto ntest = [&test]() { return !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);
|
tests.push_back(test_case);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,17 @@ TestSplit(std::string line, std::string delim, size_t maxCount, std::vector<std:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
TestSplitChar()
|
||||||
|
{
|
||||||
|
auto expected = std::vector<std::string>{"hello", "world"};
|
||||||
|
const auto *inputLine = "hello=world\n";
|
||||||
|
auto actual = U::S::SplitKeyValuePair(inputLine, '=');
|
||||||
|
|
||||||
|
return actual == expected;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
TestWrapping()
|
TestWrapping()
|
||||||
{
|
{
|
||||||
|
@ -115,7 +126,7 @@ TestWrapping()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
U::S::WriteTabIndented(std::cout, wrapped, 4, true);
|
// U::S::WriteTabIndented(std::cout, wrapped, 4, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +153,7 @@ main()
|
||||||
suite.AddTest("SplitN(0) with empty element",
|
suite.AddTest("SplitN(0) with empty element",
|
||||||
TestSplit("abc::def:ghi", ":", 0,
|
TestSplit("abc::def:ghi", ":", 0,
|
||||||
std::vector<std::string>{"abc", "", "def", "ghi"}));
|
std::vector<std::string>{"abc", "", "def", "ghi"}));
|
||||||
|
suite.AddTest("TestSplitKV(char)", TestSplitChar);
|
||||||
suite.AddTest("TextWrapping", TestWrapping);
|
suite.AddTest("TextWrapping", TestWrapping);
|
||||||
auto result = suite.Run();
|
auto result = suite.Run();
|
||||||
std::cout << suite.GetReport() << "\n";
|
std::cout << suite.GetReport() << "\n";
|
||||||
|
|
Loading…
Reference in New Issue