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

@@ -90,7 +90,7 @@ hs_database_t *get_huge(hs_database_t *db) {
}
shmaddr = shmat(hsdb_shmid, nullptr, SHM_RND);
if (shmaddr == (char *)-1) {
if (shmaddr == (char *)-1) { //NOLINT (performance-no-int-to-ptr)
perror("Shared memory attach failure");
goto fini;
}

View File

@@ -98,7 +98,7 @@ unsigned int countFailures = 0;
class ParsedExpr {
public:
ParsedExpr(string regex_in, unsigned int flags_in, const hs_expr_ext& ext_in)
: regex(regex_in), flags(flags_in), ext(ext_in) {}
: regex(std::move(regex_in)), flags(flags_in), ext(ext_in) {}
~ParsedExpr() {}
string regex;
unsigned int flags;
@@ -308,7 +308,7 @@ void checkExpression(UNUSED void *threadarg) {
ch_free_compile_error(ch_compile_err);
}
#else
cerr << "Hybrid mode not available in this build." << endl;
cerr << "Hybrid mode not available in this build.\n";
exit(1);
#endif // HS_HYBRID
} else {
@@ -468,26 +468,25 @@ void checkLogicalExpression(UNUSED void *threadarg) {
static
void usage() {
cout << "Usage: hscheck [OPTIONS...]" << endl << endl
<< " -e PATH Path to expression directory." << endl
<< " -s FILE Signature file to use." << endl
<< " -z NUM Signature ID to use." << endl
<< " -E DISTANCE Force edit distance to DISTANCE for all patterns." << endl
<< " -e PATH Path to expression directory.\n"
<< " -s FILE Signature file to use.\n"
<< " -z NUM Signature ID to use.\n"
<< " -E DISTANCE Force edit distance to DISTANCE for all patterns.\n"
#ifndef RELEASE_BUILD
<< " -G OVERRIDES Overrides for the grey." << endl
<< " -G OVERRIDES Overrides for the grey.\n"
#endif
<< " -V Operate in vectored mode." << endl
<< " -N Operate in block mode (default: streaming)." << endl
<< " -V Operate in vectored mode.\n"
<< " -N Operate in block mode (default: streaming).\n"
#ifdef HS_HYBRID
<< " -H Operate in hybrid mode." << endl
<< " -H Operate in hybrid mode.\n"
#endif
<< " -L Pass HS_FLAG_SOM_LEFTMOST for all expressions (default: off)." << endl
<< " -8 Force UTF8 mode on all patterns." << endl
<< " -T NUM Run with NUM threads." << endl
<< " -h Display this help." << endl
<< " -B Build signature set." << endl
<< " -C Check logical combinations (default: off)." << endl
<< " --literal-on Processing pure literals, no need to check." << endl
<< endl;
<< " -L Pass HS_FLAG_SOM_LEFTMOST for all expressions (default: off).\n"
<< " -8 Force UTF8 mode on all patterns.\n"
<< " -T NUM Run with NUM threads.\n"
<< " -h Display this help.\n"
<< " -B Build signature set.\n"
<< " -C Check logical combinations (default: off).\n"
<< " --literal-on Processing pure literals, no need to check.\n\n";
}
static
@@ -599,7 +598,7 @@ void failLine(unsigned lineNum, const string &file,
const string &line, const string &error) {
cerr << "Parse error in file " << file
<< " on line " << lineNum << ": " << error
<< endl << "Line is: '" << line << "'" << endl;
<< endl << "Line is: '" << line << "'\n";
exit(1);
}
@@ -612,7 +611,7 @@ void loadSignatureBuildSigs(const string &inFile,
SignatureSet &signatures) {
ifstream f(inFile.c_str());
if (!f.good()) {
cerr << "Can't open file: '" << inFile << "'" << endl;
cerr << "Can't open file: '" << inFile << "'\n";
exit(1);
}
@@ -665,7 +664,7 @@ int HS_CDECL main(int argc, char **argv) {
processArgs(argc, argv, g_grey);
if (num_of_threads == 0) {
cout << "Error: Must have at least one thread." << endl;
cout << "Error: Must have at least one thread.\n";
exit(1);
}
@@ -687,7 +686,7 @@ int HS_CDECL main(int argc, char **argv) {
}
if (g_exprMap.empty()) {
cout << "Warning: no signatures to scan. Exiting." << endl;
cout << "Warning: no signatures to scan. Exiting.\n";
exit(0);
}
@@ -717,7 +716,7 @@ int HS_CDECL main(int argc, char **argv) {
if (!g_exprMap.empty() && !build_sigs) {
cout << "SUMMARY: " << countFailures << " of "
<< g_exprMap.size() << " failed." << endl;
<< g_exprMap.size() << " failed.\n";
}
return 0;
}

View File

@@ -337,7 +337,9 @@ void clearDir(const string &path) {
if (name == "." || name == "..") {
continue;
}
string f = path + '/' + name;
string f = path;
f += '/';
f += name;
if (unlink(f.c_str()) < 0) {
printf("ERROR: couldn't remove file %s: %s\n", f.c_str(),
strerror(errno));