Bug fix/clang-tidy-performance (#300)

Various clang-tidy-performance fixes:
* noexcept
* performance-noexcept-swap
* performance
* performance-move-const-arg
* performance-unnecessary-value-param
* performance-inefficient-vector-operation
* performance-no-int-to-ptr
* add performance
* performance-inefficient-string-concatenation
* clang-analyzer-deadcode.DeadStores
* performance-inefficient-vector-operation
* clang-analyzer-core.NullDereference
* clang-analyzer-core.UndefinedBinaryOperatorResult
* clang-analyzer-core.CallAndMessage

---------

Co-authored-by: gtsoul-tech <gtsoulkanakis@gmail.com>
This commit is contained in:
gtsoul-tech
2024-06-20 14:57:19 +03:00
committed by GitHub
parent 0e0c9f8c63
commit 0f4369bf22
40 changed files with 171 additions and 170 deletions

View File

@@ -301,7 +301,7 @@ public:
// database.
hs_error_t err = hs_alloc_scratch(db, &scratch);
if (err != HS_SUCCESS) {
cerr << "ERROR: could not allocate scratch space. Exiting." << endl;
cerr << "ERROR: could not allocate scratch space. Exiting.\n";
exit(-1);
}
}
@@ -313,8 +313,7 @@ public:
size_t scratch_size;
hs_error_t err = hs_scratch_size(scratch, &scratch_size);
if (err != HS_SUCCESS) {
cerr << "ERROR: could not query scratch space size. Exiting."
<< endl;
cerr << "ERROR: could not query scratch space size. Exiting.\n";
exit(-1);
}
return scratch_size;
@@ -379,7 +378,7 @@ public:
for (auto &stream : streams) {
hs_error_t err = hs_open_stream(db, 0, &stream);
if (err != HS_SUCCESS) {
cerr << "ERROR: Unable to open stream. Exiting." << endl;
cerr << "ERROR: Unable to open stream. Exiting.\n";
exit(-1);
}
}
@@ -392,7 +391,7 @@ public:
hs_error_t err =
hs_close_stream(stream, scratch, onMatch, &matchCount);
if (err != HS_SUCCESS) {
cerr << "ERROR: Unable to close stream. Exiting." << endl;
cerr << "ERROR: Unable to close stream. Exiting.\n";
exit(-1);
}
}
@@ -407,7 +406,7 @@ public:
pkt.c_str(), pkt.length(), 0,
scratch, onMatch, &matchCount);
if (err != HS_SUCCESS) {
cerr << "ERROR: Unable to scan packet. Exiting." << endl;
cerr << "ERROR: Unable to scan packet. Exiting.\n";
exit(-1);
}
}
@@ -421,7 +420,7 @@ public:
hs_error_t err = hs_scan(db, pkt.c_str(), pkt.length(), 0,
scratch, onMatch, &matchCount);
if (err != HS_SUCCESS) {
cerr << "ERROR: Unable to scan packet. Exiting." << endl;
cerr << "ERROR: Unable to scan packet. Exiting.\n";
exit(-1);
}
}
@@ -509,29 +508,29 @@ public:
static
void usage(const char *) {
cerr << "Usage:" << endl << endl;
cerr << " patbench [-n repeats] [ -G generations] [ -C criterion ]" << endl
cerr << "Usage:\n\n";
cerr << " patbench [-n repeats] [ -G generations] [ -C criterion ]\n"
<< " [ -F factor_group_size ] [ -N | -S ] "
<< "<pattern file> <pcap file>" << endl << endl
<< "<pattern file> <pcap file>\n\n"
<< " -n repeats sets the number of times the PCAP is repeatedly "
"scanned" << endl << " with the pattern." << endl
"scanned\n" << " with the pattern.\n"
<< " -G generations sets the number of generations that the "
"algorithm is" << endl << " run for." << endl
"algorithm is\n" << " run for.\n"
<< " -N sets non-streaming mode, -S sets streaming mode (default)."
<< endl << " -F sets the factor group size (must be >0); this "
"allows the detection" << endl
<< " of multiple interacting factors." << endl << "" << endl
<< " -C sets the 'criterion', which can be either:" << endl
"allows the detection\n"
<< " of multiple interacting factors.\n" << "\n"
<< " -C sets the 'criterion', which can be either:\n"
<< " t throughput (the default) - this requires a pcap file"
<< endl << " r scratch size" << endl
<< " s stream state size" << endl
<< " c compile time" << endl << " b bytecode size"
<< endl << " r scratch size\n"
<< " s stream state size\n"
<< " c compile time\n" << " b bytecode size"
<< endl << endl
<< "We recommend the use of a utility like 'taskset' on "
"multiprocessor hosts to" << endl
"multiprocessor hosts to\n"
<< "lock execution to a single processor: this will remove processor "
"migration" << endl
<< "by the scheduler as a source of noise in the results." << endl;
"migration\n"
<< "by the scheduler as a source of noise in the results.\n";
}
static
@@ -574,7 +573,7 @@ double eval_set(Benchmark &bench, const Sigdata &sigs, unsigned int mode,
size_t dbSize;
hs_error_t err = hs_database_size(bench.getDatabase(), &dbSize);
if (err != HS_SUCCESS) {
cerr << "ERROR: could not retrieve bytecode size" << endl;
cerr << "ERROR: could not retrieve bytecode size\n";
exit(1);
}
return dbSize;
@@ -585,7 +584,7 @@ double eval_set(Benchmark &bench, const Sigdata &sigs, unsigned int mode,
size_t streamStateSize;
hs_error_t err = hs_stream_size(bench.getDatabase(), &streamStateSize);
if (err != HS_SUCCESS) {
cerr << "ERROR: could not retrieve stream state size" << endl;
cerr << "ERROR: could not retrieve stream state size\n";
exit(1);
}
return streamStateSize;
@@ -684,14 +683,13 @@ int main(int argc, char **argv) {
Benchmark bench;
if (criterion == CRITERION_THROUGHPUT) {
if (!bench.readStreams(pcapFile)) {
cerr << "Unable to read packets from PCAP file. Exiting." << endl;
cerr << "Unable to read packets from PCAP file. Exiting.\n";
exit(-1);
}
}
if ((criterion == CRITERION_STREAM_STATE) && (mode != HS_MODE_STREAM)) {
cerr << "Cannot evaluate stream state for block mode compile. Exiting."
<< endl;
cerr << "Cannot evaluate stream state for block mode compile. Exiting.\n";
exit(-1);
}
@@ -729,7 +727,7 @@ int main(int argc, char **argv) {
unsigned generations = min(gen_max, (sigs.size() - 1) / factor_max);
cout << "Cutting signatures cumulatively for " << generations
<< " generations" << endl;
<< " generations\n";
for (unsigned gen = 0; gen < generations; ++gen) {
cout << "Generation " << gen << " ";
set<unsigned> s(work_sigs.begin(), work_sigs.end());
@@ -773,7 +771,7 @@ int main(int argc, char **argv) {
cout << "Performance: ";
print_criterion(criterion, best);
cout << " (" << std::fixed << std::setprecision(3) << (best / score_base)
<< "x) after cutting:" << endl;
<< "x) after cutting:\n";
cout.flags(out_f);
// s now has factor_max signatures
@@ -852,7 +850,7 @@ static unsigned parseFlags(const string &flagsStr) {
case '\r': // stray carriage-return
break;
default:
cerr << "Unsupported flag \'" << c << "\'" << endl;
cerr << "Unsupported flag \'" << c << "\'\n";
exit(-1);
}
}
@@ -864,7 +862,7 @@ static void parseFile(const char *filename, vector<string> &patterns,
vector<string> &originals) {
ifstream inFile(filename);
if (!inFile.good()) {
cerr << "ERROR: Can't open pattern file \"" << filename << "\"" << endl;
cerr << "ERROR: Can't open pattern file \"" << filename << "\"\n";
exit(-1);
}
@@ -894,7 +892,7 @@ static void parseFile(const char *filename, vector<string> &patterns,
size_t flagsStart = expr.find_last_of('/');
if (flagsStart == string::npos) {
cerr << "ERROR: no trailing '/' char" << endl;
cerr << "ERROR: no trailing '/' char\n";
exit(-1);
}

View File

@@ -433,7 +433,7 @@ static void databasesFromFile(const char *filename,
vector<const char*> cstrPatterns;
for (const auto &pattern : patterns) {
// cppcheck-suppress useStlAlgorithm
cstrPatterns.push_back(pattern.c_str());
cstrPatterns.push_back(pattern.c_str()); //NOLINT (performance-inefficient-vector-operation)
}
cout << "Compiling Hyperscan databases with " << patterns.size()