Coverity fixes.

Primarily using std::move in more places.
This commit is contained in:
Kyle Isom 2023-10-19 21:43:38 -07:00
parent 9494871145
commit f896a108dd
9 changed files with 19 additions and 17 deletions

View File

@ -24,6 +24,7 @@ add_compile_options(
"-g" "-g"
"$<$<CONFIG:RELEASE>:-O2>" "$<$<CONFIG:RELEASE>:-O2>"
) )
#add_link_options("-fsanitize=address")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options("-stdlib=libc++") add_compile_options("-stdlib=libc++")
else () else ()
@ -40,7 +41,7 @@ set(HEADER_FILES
include/scsl/Commander.h include/scsl/Commander.h
include/scsl/Dictionary.h include/scsl/Dictionary.h
include/sctest/Exceptions.h include/sctest/Exceptions.h
include/scsl/Flag.h include/scsl/Flags.h
include/scsl/StringUtil.h include/scsl/StringUtil.h
include/scsl/TLV.h include/scsl/TLV.h
@ -65,7 +66,7 @@ set(SOURCE_FILES
src/sl/Commander.cc src/sl/Commander.cc
src/sl/Dictionary.cc src/sl/Dictionary.cc
src/test/Exceptions.cc src/test/Exceptions.cc
src/sl/Flag.cc src/sl/Flags.cc
src/sl/StringUtil.cc src/sl/StringUtil.cc
src/sl/TLV.cc src/sl/TLV.cc
@ -108,7 +109,7 @@ endmacro()
generate_test(buffer) generate_test(buffer)
generate_test(tlv) generate_test(tlv)
generate_test(dictionary) generate_test(dictionary)
generate_test(flag) generate_test(flags)
generate_test(stringutil) generate_test(stringutil)
# math and physics # math and physics

View File

@ -94,7 +94,7 @@ std::vector<std::string> SplitN(std::string, std::string delimiter, size_t maxCo
/// WrapText is a very simple wrapping function that breaks the line into /// WrapText is a very simple wrapping function that breaks the line into
/// lines of at most lineLength characters. It does this by breaking the /// lines of at most lineLength characters. It does this by breaking the
/// line into individual words (splitting on whitespace). /// line into individual words (splitting on whitespace).
std::vector<std::string> WrapText(std::string line, size_t lineLength); std::vector<std::string> WrapText(std::string& line, size_t lineLength);
/// Write out a vector of lines indented with tabs. /// Write out a vector of lines indented with tabs.
/// ///

View File

@ -33,7 +33,7 @@
#include <scsl/Commander.h> #include <scsl/Commander.h>
#include <scsl/Dictionary.h> #include <scsl/Dictionary.h>
#include <scsl/Exceptions.h> #include <scsl/Exceptions.h>
#include <scsl/Flag.h> #include <scsl/Flags.h>
#include <scsl/StringUtil.h> #include <scsl/StringUtil.h>
#include <scsl/TLV.h> #include <scsl/TLV.h>
#include <scsl/Test.h> #include <scsl/Test.h>

View File

@ -23,9 +23,10 @@
#include <iostream> #include <iostream>
#include <regex> #include <regex>
#include <utility>
#include <vector> #include <vector>
#include <scsl/Flag.h> #include <scsl/Flags.h>
#include <scsl/StringUtil.h> #include <scsl/StringUtil.h>
@ -33,7 +34,7 @@ namespace scsl {
static const std::regex isFlag("^--?[a-zA-Z0-9][a-zA-Z0-9-_]*$", static const std::regex isFlag("^--?[a-zA-Z0-9][a-zA-Z0-9-_]*$",
std::regex_constants::nosubs); std::regex_constants::nosubs|std::regex_constants::optimize);
std::string std::string
Flags::ParseStatusToString(ParseStatus status) Flags::ParseStatusToString(ParseStatus status)
@ -60,7 +61,7 @@ NewFlag(std::string fName, FlagType fType, std::string fDescription)
flag->Type = fType; flag->Type = fType;
flag->WasSet = false; flag->WasSet = false;
flag->Name = fName; flag->Name = std::move(fName);
flag->Description = fDescription; flag->Description = fDescription;
flag->Value = FlagValue{}; flag->Value = FlagValue{};
@ -69,7 +70,7 @@ NewFlag(std::string fName, FlagType fType, std::string fDescription)
Flags::Flags(std::string fName) Flags::Flags(std::string fName)
: name(fName), description("") : name(std::move(fName)), description("")
{ {
} }
@ -135,7 +136,7 @@ Flags::Register(std::string fName, int defaultValue, std::string fDescription)
bool bool
Flags::Register(std::string fName, unsigned int defaultValue, std::string fDescription) Flags::Register(std::string fName, unsigned int defaultValue, std::string fDescription)
{ {
if (!this->Register(fName, FlagType::UnsignedInteger, fDescription)) { if (!this->Register(fName, FlagType::UnsignedInteger, std::move(fDescription))) {
return false; return false;
} }
@ -147,7 +148,7 @@ Flags::Register(std::string fName, unsigned int defaultValue, std::string fDescr
bool bool
Flags::Register(std::string fName, size_t defaultValue, std::string fDescription) Flags::Register(std::string fName, size_t defaultValue, std::string fDescription)
{ {
if (!this->Register(fName, FlagType::SizeT, fDescription)) { if (!this->Register(fName, FlagType::SizeT, std::move(fDescription))) {
return false; return false;
} }

View File

@ -38,7 +38,7 @@ namespace S {
std::vector<std::string> std::vector<std::string>
SplitKeyValuePair(std::string line, std::string delimiter) SplitKeyValuePair(std::string line, std::string delimiter)
{ {
auto pair = SplitN(line, delimiter, 2); auto pair = SplitN(std::move(line), delimiter, 2);
if (pair.size() == 0) { if (pair.size() == 0) {
return {"", ""}; return {"", ""};
@ -61,7 +61,7 @@ SplitKeyValuePair(std::string line, char delimiter)
{ {
std::string sDelim; std::string sDelim;
sDelim.push_back(delimiter); sDelim.push_back(std::move(delimiter));
return SplitKeyValuePair(line, sDelim); return SplitKeyValuePair(line, sDelim);
} }
@ -143,7 +143,7 @@ SplitN(std::string s, std::string delim, size_t maxCount)
std::vector<std::string> std::vector<std::string>
WrapText(std::string line, size_t lineLength) WrapText(std::string& line, size_t lineLength)
{ {
std::vector<std::string> wrapped; std::vector<std::string> wrapped;
auto parts = SplitN(line, " ", 0); auto parts = SplitN(line, " ", 0);

View File

@ -35,7 +35,7 @@ Assert(bool condition, std::string message)
{ {
#if defined(NDEBUG) || defined(SCSL_NOEXCEPT) #if defined(NDEBUG) || defined(SCSL_NOEXCEPT)
if (!condition) { if (!condition) {
throw AssertionFailed(message); throw AssertionFailed(std::move(message));
} }
#else #else
if (!condition) { if (!condition) {

View File

@ -4,7 +4,7 @@
#include <iostream> #include <iostream>
#include <scsl/Flag.h> #include <scsl/Flags.h>
#include <sctest/Assert.h> #include <sctest/Assert.h>

View File

@ -1,4 +1,4 @@
#include <scsl/Flag.h> #include <scsl/Flags.h>
#include <scmp/Math.h> #include <scmp/Math.h>
#include <scmp/geom/Vector.h> #include <scmp/geom/Vector.h>