diff --git a/.clang-tidy b/.clang-tidy index 79ec9065..4cadbbb4 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,9 +1,11 @@ #unit/gtest/gtest-all.cc,build/src/parser/Parser.cpp,build/src/parser/control_verbs.cpp #Dont change first comment ignores specific files from clang-tidy -Checks: 'clang-analyzer-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling' + +Checks: 'clang-analyzer-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,performance-*,-performance-unnecessary-value-param,-performance-avoid-endl' WarningsAsErrors: '' HeaderFilterRegex: '.*' +SystemHeaders: false FormatStyle: none InheritParentConfig: true -User: user +User: user \ No newline at end of file diff --git a/examples/patbench.cc b/examples/patbench.cc index 1a7e9415..4576bfe0 100644 --- a/examples/patbench.cc +++ b/examples/patbench.cc @@ -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 ] " - << " " << endl << endl + << " \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 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 &patterns, vector &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 &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); } diff --git a/examples/pcapscan.cc b/examples/pcapscan.cc index f4feb573..7dcc8dc4 100644 --- a/examples/pcapscan.cc +++ b/examples/pcapscan.cc @@ -433,7 +433,7 @@ static void databasesFromFile(const char *filename, vector 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() diff --git a/src/fdr/fdr.c b/src/fdr/fdr.c index 302487a3..7aa22ef5 100644 --- a/src/fdr/fdr.c +++ b/src/fdr/fdr.c @@ -308,7 +308,7 @@ void do_confirm_fdr(u64a *conf, u8 offset, hwlmcb_rv_t *control, /* ptr is currently referring to a location in the zone's buffer, we also * need a pointer in the original, main buffer for the final string compare. */ - const u8 *ptr_main = (const u8 *)((uintptr_t)ptr + z->zone_pointer_adjust); + const u8 *ptr_main = (const u8 *)((uintptr_t)ptr + z->zone_pointer_adjust); //NOLINT (performance-no-int-to-ptr) const u8 *confLoc = ptr; diff --git a/src/nfa/goughcompile_dump.cpp b/src/nfa/goughcompile_dump.cpp index 649310c6..8fca295a 100644 --- a/src/nfa/goughcompile_dump.cpp +++ b/src/nfa/goughcompile_dump.cpp @@ -146,7 +146,7 @@ void dump_var_mapping(const GoughGraph &g, const string &base, vector used_id; for (const GoughSSAVar *var : used) { // cppcheck-suppress useStlAlgorithm - used_id.emplace_back(var->slot); + used_id.emplace_back(var->slot); //NOLINT (performance-inefficient-vector-operation) } for (const u32 &id : used_id) { fprintf(f, " %u", id); @@ -169,7 +169,7 @@ void dump_var_mapping(const GoughGraph &g, const string &base, vector used_id; for (const GoughSSAVar *var : used) { // cppcheck-suppress useStlAlgorithm - used_id.emplace_back(var->slot); + used_id.emplace_back(var->slot); //NOLINT (performance-inefficient-vector-operation) } for (const u32 &id : used_id) { fprintf(f, " %u", id); diff --git a/src/nfa/limex_compile.cpp b/src/nfa/limex_compile.cpp index 304116a8..39214bd8 100644 --- a/src/nfa/limex_compile.cpp +++ b/src/nfa/limex_compile.cpp @@ -628,7 +628,7 @@ void fillAccelInfo(build_info &bi) { vector astates; for (const auto &m : accel_map) { // cppcheck-suppress useStlAlgorithm - astates.emplace_back(m.first); + astates.emplace_back(m.first); //NOLINT (performance-inefficient-vector-operation) } NFAStateSet useful(num_states); @@ -1071,7 +1071,7 @@ void buildAcceptsList(const build_info &args, ReportListCache &reports_cache, a.reports = addReports(h[v].reports, reports, reports_cache); } a.squash = addSquashMask(args, v, squash); - accepts.emplace_back(std::move(a)); + accepts.emplace_back(a); } } diff --git a/src/nfa/sheng_impl.h b/src/nfa/sheng_impl.h index 8b22d810..0204b872 100644 --- a/src/nfa/sheng_impl.h +++ b/src/nfa/sheng_impl.h @@ -143,7 +143,7 @@ char SHENG32_IMPL(u8 *state, NfaCallback cb, void *ctxt, if (unlikely(ACCEPT_FUNC32(tmp))) { DEBUG_PRINTF("Accept state %u reached\n", tmp & SHENG32_STATE_MASK); - u64a match_offset = base_offset + (cur_buf - buf) + 1; + u64a match_offset = base_offset + (cur_buf - buf) + 1; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("Match @ %llu\n", match_offset); if (STOP_AT_MATCH) { DEBUG_PRINTF("Stopping at match @ %lli\n", @@ -222,7 +222,7 @@ char SHENG64_IMPL(u8 *state, NfaCallback cb, void *ctxt, if (unlikely(ACCEPT_FUNC64(tmp))) { DEBUG_PRINTF("Accept state %u reached\n", tmp & SHENG64_STATE_MASK); - u64a match_offset = base_offset + (cur_buf - buf) + 1; + u64a match_offset = base_offset + (cur_buf - buf) + 1; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("Match @ %llu\n", match_offset); if (STOP_AT_MATCH) { DEBUG_PRINTF("Stopping at match @ %lli\n", diff --git a/src/nfa/sheng_impl4.h b/src/nfa/sheng_impl4.h index d2b3dc35..40642a60 100644 --- a/src/nfa/sheng_impl4.h +++ b/src/nfa/sheng_impl4.h @@ -392,7 +392,7 @@ char SHENG32_IMPL(u8 *state, NfaCallback cb, void *ctxt, if (unlikely(INTERESTING_FUNC32(a1, a2, a3, a4))) { if (ACCEPT_FUNC32(a1)) { - u64a match_offset = base_offset + b1 - buf; + u64a match_offset = base_offset + b1 - buf; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("Accept state %u reached\n", a1 & SHENG32_STATE_MASK); DEBUG_PRINTF("Match @ %llu\n", match_offset); @@ -417,7 +417,7 @@ char SHENG32_IMPL(u8 *state, NfaCallback cb, void *ctxt, } } if (ACCEPT_FUNC32(a2)) { - u64a match_offset = base_offset + b2 - buf; + u64a match_offset = base_offset + b2 - buf; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("Accept state %u reached\n", a2 & SHENG32_STATE_MASK); DEBUG_PRINTF("Match @ %llu\n", match_offset); @@ -442,7 +442,7 @@ char SHENG32_IMPL(u8 *state, NfaCallback cb, void *ctxt, } } if (ACCEPT_FUNC32(a3)) { - u64a match_offset = base_offset + b3 - buf; + u64a match_offset = base_offset + b3 - buf; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("Accept state %u reached\n", a3 & SHENG32_STATE_MASK); DEBUG_PRINTF("Match @ %llu\n", match_offset); @@ -467,7 +467,7 @@ char SHENG32_IMPL(u8 *state, NfaCallback cb, void *ctxt, } } if (ACCEPT_FUNC32(a4)) { - u64a match_offset = base_offset + b4 - buf; + u64a match_offset = base_offset + b4 - buf; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("Accept state %u reached\n", a4 & SHENG32_STATE_MASK); DEBUG_PRINTF("Match @ %llu\n", match_offset); @@ -642,7 +642,7 @@ char SHENG64_IMPL(u8 *state, NfaCallback cb, void *ctxt, if (unlikely(INTERESTING_FUNC64(a1, a2, a3, a4))) { if (ACCEPT_FUNC64(a1)) { - u64a match_offset = base_offset + b1 - buf; + u64a match_offset = base_offset + b1 - buf; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("Accept state %u reached\n", a1 & SHENG64_STATE_MASK); DEBUG_PRINTF("Match @ %llu\n", match_offset); @@ -667,7 +667,7 @@ char SHENG64_IMPL(u8 *state, NfaCallback cb, void *ctxt, } } if (ACCEPT_FUNC64(a2)) { - u64a match_offset = base_offset + b2 - buf; + u64a match_offset = base_offset + b2 - buf; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("Accept state %u reached\n", a2 & SHENG64_STATE_MASK); DEBUG_PRINTF("Match @ %llu\n", match_offset); @@ -692,7 +692,7 @@ char SHENG64_IMPL(u8 *state, NfaCallback cb, void *ctxt, } } if (ACCEPT_FUNC64(a3)) { - u64a match_offset = base_offset + b3 - buf; + u64a match_offset = base_offset + b3 - buf; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("Accept state %u reached\n", a3 & SHENG64_STATE_MASK); DEBUG_PRINTF("Match @ %llu\n", match_offset); @@ -717,7 +717,7 @@ char SHENG64_IMPL(u8 *state, NfaCallback cb, void *ctxt, } } if (ACCEPT_FUNC64(a4)) { - u64a match_offset = base_offset + b4 - buf; + u64a match_offset = base_offset + b4 - buf; //NOLINT (clang-analyzer-deadcode.DeadStores) DEBUG_PRINTF("Accept state %u reached\n", a4 & SHENG64_STATE_MASK); DEBUG_PRINTF("Match @ %llu\n", match_offset); diff --git a/src/nfa/truffle_simd.hpp b/src/nfa/truffle_simd.hpp index 61609a39..2e8ecb9a 100644 --- a/src/nfa/truffle_simd.hpp +++ b/src/nfa/truffle_simd.hpp @@ -104,9 +104,9 @@ const u8 *scanBlock(svuint8_t shuf_mask_lo_highclear, svuint8_t shuf_mask_lo_hig } uint64_t index; if (forward) { - index = first_non_zero(vector_size_int_8, result_mask); + index = first_non_zero(vector_size_int_8, result_mask); //NOLINT (clang-analyzer-core.CallAndMessage) } else { - index = last_non_zero(vector_size_int_8, result_mask); + index = last_non_zero(vector_size_int_8, result_mask); //NOLINT (clang-analyzer-core.CallAndMessage) } if (index < vector_size_int_8) { @@ -311,7 +311,7 @@ const u8 *truffleExecReal(const m128 &shuf_mask_lo_highclear, m128 shuf_mask_lo_ SuperVector chars = SuperVector::Zeroes(); const u8* end_buf; if (buf_end - buf < S) { - memcpy(&chars.u, buf, buf_end - buf); + memcpy(&chars.u, buf, buf_end - buf); //NOLINT (clang-analyzer-core.NonNullParamChecker) end_buf = buf; } else { chars = SuperVector::loadu(buf_end - S); diff --git a/src/nfa/vermicelli_sve.h b/src/nfa/vermicelli_sve.h index 13f84341..184be1bf 100644 --- a/src/nfa/vermicelli_sve.h +++ b/src/nfa/vermicelli_sve.h @@ -379,7 +379,7 @@ const u8 *vermicelliDoubleExec(char c1, char c2, bool nocase, const u8 *buf, } /* check for partial match at end */ u8 mask = nocase ? CASE_CLEAR : 0xff; - if ((buf_end[-1] & mask) == (u8)c1) { + if ((buf_end[-1] & mask) == (u8)c1) { //NOLINT (clang-analyzer-core.NullDereference) DEBUG_PRINTF("partial!!!\n"); return buf_end - 1; } @@ -486,7 +486,7 @@ const u8 *vermicelliDoubleMasked16Exec(const m128 mask, char c1, char m1, } } /* check for partial match at end */ - if ((buf_end[-1] & m1) == (u8)c1) { + if ((buf_end[-1] & m1) == (u8)c1) { //NOLINT (clang-analyzer-core.NullDereference) DEBUG_PRINTF("partial!!!\n"); return buf_end - 1; } @@ -523,7 +523,7 @@ const u8 *dvermSearchAlignedMasked(m128 chars1, m128 chars2, m128 v2 = eq128(chars2, and128(data, mask2)); u32 z = movemask128(and128(v1, rshiftbyte_m128(v2, 1))); - if ((buf[15] & m1) == c1 && (buf[16] & m2) == c2) { + if ((buf[15] & m1) == c1 && (buf[16] & m2) == c2) { //NOLINT (clang-analyzer-core.NullDereference) z |= (1 << 15); } if (unlikely(z)) { @@ -579,7 +579,7 @@ const u8 *vermicelliDoubleMaskedExec(char c1, char c2, char m1, char m2, } /* check for partial match at end */ - if ((buf_end[-1] & m1) == (u8)c1) { + if ((buf_end[-1] & m1) == (u8)c1) { //NOLINT (clang-analyzer-core.NullDereference) DEBUG_PRINTF("partial!!!\n"); return buf_end - 1; } diff --git a/src/nfagraph/ng_limex_accel.cpp b/src/nfagraph/ng_limex_accel.cpp index 21e7fa05..226f748a 100644 --- a/src/nfagraph/ng_limex_accel.cpp +++ b/src/nfagraph/ng_limex_accel.cpp @@ -190,7 +190,7 @@ void findPaths(const NGHolder &g, NFAVertex v, namespace { struct SAccelScheme { SAccelScheme(CharReach cr_in, u32 offset_in) - : cr(std::move(cr_in)), offset(offset_in) { + : cr(cr_in), offset(offset_in) { assert(offset <= MAX_ACCEL_DEPTH); } @@ -254,7 +254,7 @@ void findBestInternal(vector>::const_iterator pb, DEBUG_PRINTF("worse\n"); continue; } - priority_path.emplace_back(std::move(as)); + priority_path.emplace_back(as); } sort(priority_path.begin(), priority_path.end()); @@ -300,7 +300,7 @@ SAccelScheme findBest(const vector> &paths, namespace { struct DAccelScheme { DAccelScheme(CharReach cr_in, u32 offset_in) - : double_cr(std::move(cr_in)), double_offset(offset_in) { + : double_cr(cr_in), double_offset(offset_in) { assert(double_offset <= MAX_ACCEL_DEPTH); } @@ -570,7 +570,7 @@ AccelScheme findBestAccelScheme(vector> paths, DAccelScheme da = findBestDoubleAccelScheme(paths, terminating); if (da.double_byte.size() <= DOUBLE_SHUFTI_LIMIT) { rv.double_byte = std::move(da.double_byte); - rv.double_cr = std::move(da.double_cr); + rv.double_cr = da.double_cr; rv.double_offset = da.double_offset; } } diff --git a/src/nfagraph/ng_literal_analysis.cpp b/src/nfagraph/ng_literal_analysis.cpp index 178f5aa3..119bd33f 100644 --- a/src/nfagraph/ng_literal_analysis.cpp +++ b/src/nfagraph/ng_literal_analysis.cpp @@ -68,7 +68,7 @@ namespace { struct LitGraphVertexProps { LitGraphVertexProps() = default; - explicit LitGraphVertexProps(ue2_literal::elem c_in) : c(std::move(c_in)) {} + explicit LitGraphVertexProps(ue2_literal::elem c_in) : c(c_in) {} ue2_literal::elem c; // string element (char + bool) size_t index = 0; // managed by ue2_graph }; diff --git a/src/nfagraph/ng_mcclellan.cpp b/src/nfagraph/ng_mcclellan.cpp index 3b6c0760..98c1e354 100644 --- a/src/nfagraph/ng_mcclellan.cpp +++ b/src/nfagraph/ng_mcclellan.cpp @@ -380,7 +380,7 @@ public: u32 vert_id = graph[v].index; squash.set(vert_id); squash_mask[vert_id] - = Automaton_Traits::copy_states(std::move(sq.second), + = Automaton_Traits::copy_states(sq.second, numStates); } diff --git a/src/parser/parse_error.h b/src/parser/parse_error.h index 4556ed5e..9bd17f6c 100644 --- a/src/parser/parse_error.h +++ b/src/parser/parse_error.h @@ -44,7 +44,7 @@ class ParseError : public CompileError { public: // Note: 'why' should describe why the error occurred and end with a // full stop, but no line break. - explicit ParseError(std::string why) : CompileError(std::move(why)) {} + explicit ParseError(const std::string& why) : CompileError(why) {} ~ParseError() override; }; diff --git a/src/rose/program_runtime.c b/src/rose/program_runtime.c index bedc8264..1273f799 100644 --- a/src/rose/program_runtime.c +++ b/src/rose/program_runtime.c @@ -788,7 +788,7 @@ int roseCheckMask32(const struct core_info *ci, const u8 *and_mask, DEBUG_PRINTF("h_len %d c_len %d\n", h_len, c_len); // we use valid_data_mask to blind bytes before history/in the future. u32 valid_data_mask; - valid_data_mask = (~0u) << (h_shift + c_shift) >> (c_shift); + valid_data_mask = (~0u) << (h_shift + c_shift) >> (c_shift); //NOLINT (clang-analyzer-core.UndefinedBinaryOperatorResult) m256 and_mask_m256 = loadu256(and_mask); m256 cmp_mask_m256 = loadu256(cmp_mask); diff --git a/src/rose/rose_build_bytecode.cpp b/src/rose/rose_build_bytecode.cpp index 9c7bb6fd..c2316f9f 100644 --- a/src/rose/rose_build_bytecode.cpp +++ b/src/rose/rose_build_bytecode.cpp @@ -1954,7 +1954,7 @@ bool buildSuffixes(const RoseBuildImpl &tbi, build_context &bc, vector> ordered; for (const auto &e : bc.suffixes) { // cppcheck-suppress useStlAlgorithm - ordered.emplace_back(e.second, e.first); + ordered.emplace_back(e.second, e.first); //NOLINT (performance-inefficient-vector-operation) } sort(begin(ordered), end(ordered)); diff --git a/src/rose/rose_build_instructions.h b/src/rose/rose_build_instructions.h index 01ff8d88..2c1c7c6a 100644 --- a/src/rose/rose_build_instructions.h +++ b/src/rose/rose_build_instructions.h @@ -393,7 +393,7 @@ public: RoseInstrCheckSingleLookaround(s8 offset_in, CharReach reach_in, const RoseInstruction *target_in) - : offset(offset_in), reach(std::move(reach_in)), target(target_in) {} + : offset(offset_in), reach(reach_in), target(target_in) {} bool operator==(const RoseInstrCheckSingleLookaround &ri) const { return offset == ri.offset && reach == ri.reach && target == ri.target; @@ -495,7 +495,7 @@ public: RoseInstrCheckMask32(std::array and_mask_in, std::array cmp_mask_in, u32 neg_mask_in, s32 offset_in, const RoseInstruction *target_in) - : and_mask(std::move(and_mask_in)), cmp_mask(std::move(cmp_mask_in)), + : and_mask(and_mask_in), cmp_mask(cmp_mask_in), neg_mask(neg_mask_in), offset(offset_in), target(target_in) {} bool operator==(const RoseInstrCheckMask32 &ri) const { @@ -533,7 +533,7 @@ public: RoseInstrCheckMask64(std::array and_mask_in, std::array cmp_mask_in, u64a neg_mask_in, s32 offset_in, const RoseInstruction *target_in) - : and_mask(std::move(and_mask_in)), cmp_mask(std::move(cmp_mask_in)), + : and_mask(and_mask_in), cmp_mask(cmp_mask_in), neg_mask(neg_mask_in), offset(offset_in), target(target_in) {} bool operator==(const RoseInstrCheckMask64 &ri) const { return and_mask == ri.and_mask && cmp_mask == ri.cmp_mask && @@ -608,8 +608,8 @@ public: std::array bucket_select_mask_in, u32 neg_mask_in, s32 offset_in, const RoseInstruction *target_in) - : nib_mask(std::move(nib_mask_in)), - bucket_select_mask(std::move(bucket_select_mask_in)), + : nib_mask(nib_mask_in), + bucket_select_mask(bucket_select_mask_in), neg_mask(neg_mask_in), offset(offset_in), target(target_in) {} bool operator==(const RoseInstrCheckShufti16x8 &ri) const { @@ -652,8 +652,8 @@ public: std::array bucket_select_mask_in, u32 neg_mask_in, s32 offset_in, const RoseInstruction *target_in) - : hi_mask(std::move(hi_mask_in)), lo_mask(std::move(lo_mask_in)), - bucket_select_mask(std::move(bucket_select_mask_in)), + : hi_mask(hi_mask_in), lo_mask(lo_mask_in), + bucket_select_mask(bucket_select_mask_in), neg_mask(neg_mask_in), offset(offset_in), target(target_in) {} bool operator==(const RoseInstrCheckShufti32x8 &ri) const { @@ -697,8 +697,8 @@ public: std::array bucket_select_mask_in, u32 neg_mask_in, s32 offset_in, const RoseInstruction *target_in) - : hi_mask(std::move(hi_mask_in)), lo_mask(std::move(lo_mask_in)), - bucket_select_mask(std::move(bucket_select_mask_in)), + : hi_mask(hi_mask_in), lo_mask(lo_mask_in), + bucket_select_mask(bucket_select_mask_in), neg_mask(neg_mask_in), offset(offset_in), target(target_in) {} bool operator==(const RoseInstrCheckShufti16x16 &ri) const { @@ -744,9 +744,9 @@ public: std::array bucket_select_mask_lo_in, u32 neg_mask_in, s32 offset_in, const RoseInstruction *target_in) - : hi_mask(std::move(hi_mask_in)), lo_mask(std::move(lo_mask_in)), - bucket_select_mask_hi(std::move(bucket_select_mask_hi_in)), - bucket_select_mask_lo(std::move(bucket_select_mask_lo_in)), + : hi_mask(hi_mask_in), lo_mask(lo_mask_in), + bucket_select_mask_hi(bucket_select_mask_hi_in), + bucket_select_mask_lo(bucket_select_mask_lo_in), neg_mask(neg_mask_in), offset(offset_in), target(target_in) {} bool operator==(const RoseInstrCheckShufti32x16 &ri) const { @@ -792,8 +792,8 @@ public: std::array bucket_select_mask_in, u64a neg_mask_in, s32 offset_in, const RoseInstruction *target_in) - : hi_mask(std::move(hi_mask_in)), lo_mask(std::move(lo_mask_in)), - bucket_select_mask(std::move(bucket_select_mask_in)), + : hi_mask(hi_mask_in), lo_mask(lo_mask_in), + bucket_select_mask(bucket_select_mask_in), neg_mask(neg_mask_in), offset(offset_in), target(target_in) {} bool operator==(const RoseInstrCheckShufti64x8 &ri) const { @@ -843,10 +843,10 @@ public: std::array bucket_select_mask_lo_in, u64a neg_mask_in, s32 offset_in, const RoseInstruction *target_in) - : hi_mask_1(std::move(hi_mask_1_in)), hi_mask_2(std::move(hi_mask_2_in)), - lo_mask_1(std::move(lo_mask_1_in)), lo_mask_2(std::move(lo_mask_2_in)), - bucket_select_mask_hi(std::move(bucket_select_mask_hi_in)), - bucket_select_mask_lo(std::move(bucket_select_mask_lo_in)), + : hi_mask_1(hi_mask_1_in), hi_mask_2(hi_mask_2_in), + lo_mask_1(lo_mask_1_in), lo_mask_2(lo_mask_2_in), + bucket_select_mask_hi(bucket_select_mask_hi_in), + bucket_select_mask_lo(bucket_select_mask_lo_in), neg_mask(neg_mask_in), offset(offset_in), target(target_in) {} bool operator==(const RoseInstrCheckShufti64x16 &ri) const { @@ -1978,7 +1978,7 @@ public: std::array start_mask_in, const RoseInstruction *target_in) : multi_look(std::move(ml)), last_start(last_start_in), - start_mask(std::move(start_mask_in)), target(target_in) {} + start_mask(start_mask_in), target(target_in) {} bool operator==(const RoseInstrMultipathLookaround &ri) const { return multi_look == ri.multi_look && last_start == ri.last_start @@ -2023,9 +2023,9 @@ public: u16 neg_mask_in, s32 base_offset_in, s32 last_start_in, const RoseInstruction *target_in) - : nib_mask(std::move(nib_mask_in)), - bucket_select_mask(std::move(bucket_select_mask_in)), - data_select_mask(std::move(data_select_mask_in)), + : nib_mask(nib_mask_in), + bucket_select_mask(bucket_select_mask_in), + data_select_mask(data_select_mask_in), hi_bits_mask(hi_bits_mask_in), lo_bits_mask(lo_bits_mask_in), neg_mask(neg_mask_in), base_offset(base_offset_in), last_start(last_start_in), target(target_in) {} @@ -2086,9 +2086,9 @@ public: u32 neg_mask_in, s32 base_offset_in, s32 last_start_in, const RoseInstruction *target_in) - : hi_mask(std::move(hi_mask_in)), lo_mask(std::move(lo_mask_in)), - bucket_select_mask(std::move(bucket_select_mask_in)), - data_select_mask(std::move(data_select_mask_in)), + : hi_mask(hi_mask_in), lo_mask(lo_mask_in), + bucket_select_mask(bucket_select_mask_in), + data_select_mask(data_select_mask_in), hi_bits_mask(hi_bits_mask_in), lo_bits_mask(lo_bits_mask_in), neg_mask(neg_mask_in), base_offset(base_offset_in), last_start(last_start_in), target(target_in) {} @@ -2151,10 +2151,10 @@ public: u32 neg_mask_in, s32 base_offset_in, s32 last_start_in, const RoseInstruction *target_in) - : hi_mask(std::move(hi_mask_in)), lo_mask(std::move(lo_mask_in)), - bucket_select_mask_hi(std::move(bucket_select_mask_hi_in)), - bucket_select_mask_lo(std::move(bucket_select_mask_lo_in)), - data_select_mask(std::move(data_select_mask_in)), + : hi_mask(hi_mask_in), lo_mask(lo_mask_in), + bucket_select_mask_hi(bucket_select_mask_hi_in), + bucket_select_mask_lo(bucket_select_mask_lo_in), + data_select_mask(data_select_mask_in), hi_bits_mask(hi_bits_mask_in), lo_bits_mask(lo_bits_mask_in), neg_mask(neg_mask_in), base_offset(base_offset_in), last_start(last_start_in), target(target_in) {} @@ -2217,9 +2217,9 @@ public: u64a neg_mask_in, s32 base_offset_in, s32 last_start_in, const RoseInstruction *target_in) - : hi_mask(std::move(hi_mask_in)), lo_mask(std::move(lo_mask_in)), - bucket_select_mask(std::move(bucket_select_mask_in)), - data_select_mask(std::move(data_select_mask_in)), + : hi_mask(hi_mask_in), lo_mask(lo_mask_in), + bucket_select_mask(bucket_select_mask_in), + data_select_mask(data_select_mask_in), hi_bits_mask(hi_bits_mask_in), lo_bits_mask(lo_bits_mask_in), neg_mask(neg_mask_in), base_offset(base_offset_in), last_start(last_start_in), target(target_in) {} diff --git a/src/rose/rose_build_lookaround.cpp b/src/rose/rose_build_lookaround.cpp index 7c203be5..fd7913e2 100644 --- a/src/rose/rose_build_lookaround.cpp +++ b/src/rose/rose_build_lookaround.cpp @@ -466,7 +466,7 @@ void findFloodReach(const RoseBuildImpl &tbi, const RoseVertex v, namespace { struct LookProto { LookProto(s32 offset_in, CharReach reach_in) - : offset(offset_in), reach(std::move(reach_in)) {} + : offset(offset_in), reach(reach_in) {} s32 offset; CharReach reach; }; diff --git a/src/rose/rose_build_matchers.cpp b/src/rose/rose_build_matchers.cpp index a14eae2d..a980d14f 100644 --- a/src/rose/rose_build_matchers.cpp +++ b/src/rose/rose_build_matchers.cpp @@ -739,7 +739,7 @@ void addFragmentLiteral(const RoseBuildImpl &build, MatcherProto &mp, const auto &groups = f.groups; - mp.lits.emplace_back(std::move(s_final), nocase, noruns, f.fragment_id, + mp.lits.emplace_back(s_final, nocase, noruns, f.fragment_id, groups, msk, lcmp); } diff --git a/src/rose/rose_build_matchers.h b/src/rose/rose_build_matchers.h index 37a96c7a..d4fc3421 100644 --- a/src/rose/rose_build_matchers.h +++ b/src/rose/rose_build_matchers.h @@ -52,11 +52,11 @@ static constexpr u32 INVALID_FRAG_ID = ~0U; struct LitFragment { LitFragment(u32 fragment_id_in, ue2_literal s_in, rose_group groups_in, u32 lit_id) - : fragment_id(fragment_id_in), s(s_in), groups(groups_in), + : fragment_id(fragment_id_in), s(std::move(s_in)), groups(groups_in), lit_ids({lit_id}) {} LitFragment(u32 fragment_id_in, ue2_literal s_in, rose_group groups_in, std::vector lit_ids_in) - : fragment_id(fragment_id_in), s(s_in), groups(groups_in), + : fragment_id(fragment_id_in), s(std::move(s_in)), groups(groups_in), lit_ids(std::move(lit_ids_in)) {} u32 fragment_id; diff --git a/src/rose/rose_build_program.cpp b/src/rose/rose_build_program.cpp index a157ad27..11c7aba3 100644 --- a/src/rose/rose_build_program.cpp +++ b/src/rose/rose_build_program.cpp @@ -100,8 +100,8 @@ RoseProgram::RoseProgram() { RoseProgram::~RoseProgram() = default; -RoseProgram::RoseProgram(RoseProgram &&) = default; -RoseProgram &RoseProgram::operator=(RoseProgram &&) = default; +RoseProgram::RoseProgram(RoseProgram &&) noexcept = default; +RoseProgram &RoseProgram::operator=(RoseProgram &&) noexcept = default; bool RoseProgram::empty() const { assert(!prog.empty()); diff --git a/src/rose/rose_build_program.h b/src/rose/rose_build_program.h index 1882279d..b8323dc8 100644 --- a/src/rose/rose_build_program.h +++ b/src/rose/rose_build_program.h @@ -57,9 +57,9 @@ public: RoseProgram(); ~RoseProgram(); RoseProgram(const RoseProgram &) = delete; - RoseProgram(RoseProgram &&); + RoseProgram(RoseProgram &&) noexcept; RoseProgram &operator=(const RoseProgram &) = delete; - RoseProgram &operator=(RoseProgram &&); + RoseProgram &operator=(RoseProgram &&) noexcept; bool empty() const; diff --git a/src/rose/rose_in_graph.h b/src/rose/rose_in_graph.h index da0ea08d..1cfcf305 100644 --- a/src/rose/rose_in_graph.h +++ b/src/rose/rose_in_graph.h @@ -143,7 +143,7 @@ struct RoseInEdgeProps { /* haig rosefixes (prefix/infix) require their corresponding holders */ RoseInEdgeProps(std::shared_ptr g, std::shared_ptr h, u32 lag) - : minBound(0), maxBound(ROSE_BOUND_INF), graph(g), haig(h), + : minBound(0), maxBound(ROSE_BOUND_INF), graph(std::move(g)), haig(std::move(h)), graph_lag(lag) { assert(graph); assert(haig); @@ -151,12 +151,12 @@ struct RoseInEdgeProps { /* haig suffixes do not require their corresponding holders */ explicit RoseInEdgeProps(std::shared_ptr h) - : minBound(0), maxBound(ROSE_BOUND_INF), haig(h), graph_lag(0) { + : minBound(0), maxBound(ROSE_BOUND_INF), haig(std::move(h)), graph_lag(0) { assert(haig); } RoseInEdgeProps(std::shared_ptr g, u32 lag) - : minBound(0), maxBound(ROSE_BOUND_INF), graph(g), graph_lag(lag) { + : minBound(0), maxBound(ROSE_BOUND_INF), graph(std::move(g)), graph_lag(lag) { assert(graph); } diff --git a/src/som/slot_manager_internal.h b/src/som/slot_manager_internal.h index 7e1fecc7..8f63da55 100644 --- a/src/som/slot_manager_internal.h +++ b/src/som/slot_manager_internal.h @@ -46,7 +46,7 @@ struct InitialResetEntry { std::shared_ptr body_in, const std::unordered_map &body_regions_in, u32 sent_region_in, u32 first_bad_region_in) - : sent(sent_in), body(body_in), body_regions(body_regions_in), + : sent(sent_in), body(std::move(body_in)), body_regions(body_regions_in), sent_region(sent_region_in), first_bad_region(first_bad_region_in) {} std::shared_ptr sent; diff --git a/src/ue2common.h b/src/ue2common.h index b8300dc7..525fb26c 100644 --- a/src/ue2common.h +++ b/src/ue2common.h @@ -112,8 +112,8 @@ typedef u32 ReportID; // Align ptr to next N-byte boundary #if defined(HAVE_TYPEOF) -#define ROUNDUP_PTR(ptr, n) (__typeof__(ptr))(ROUNDUP_N((uintptr_t)(ptr), (n))) -#define ROUNDDOWN_PTR(ptr, n) (__typeof__(ptr))(ROUNDDOWN_N((uintptr_t)(ptr), (n))) +#define ROUNDUP_PTR(ptr, n) (__typeof__(ptr))(ROUNDUP_N((uintptr_t)(ptr), (n))) //NOLINT (performance-no-int-to-ptr) +#define ROUNDDOWN_PTR(ptr, n) (__typeof__(ptr))(ROUNDDOWN_N((uintptr_t)(ptr), (n))) //NOLINT (performance-no-int-to-ptr) #else #define ROUNDUP_PTR(ptr, n) (void*)(ROUNDUP_N((uintptr_t)(ptr), (n))) #define ROUNDDOWN_PTR(ptr, n) (void*)(ROUNDDOWN_N((uintptr_t)(ptr), (n))) diff --git a/src/util/bytecode_ptr.h b/src/util/bytecode_ptr.h index ab2b9171..210b0636 100644 --- a/src/util/bytecode_ptr.h +++ b/src/util/bytecode_ptr.h @@ -95,7 +95,7 @@ public: return p; } - void swap(bytecode_ptr &other) { + void swap(bytecode_ptr &other) noexcept { using std::swap; swap(ptr, other.ptr); swap(bytes, other.bytes); diff --git a/src/util/flat_containers.h b/src/util/flat_containers.h index b3dce4fa..2463f9d1 100644 --- a/src/util/flat_containers.h +++ b/src/util/flat_containers.h @@ -131,7 +131,7 @@ public: data().clear(); } - void swap(flat_base &a) { + void swap(flat_base &a) noexcept { using std::swap; swap(comp(), a.comp()); swap(data(), a.data()); @@ -215,9 +215,9 @@ public: } flat_set(const flat_set &) = default; - flat_set(flat_set &&) = default; + flat_set(flat_set &&) noexcept = default; flat_set &operator=(const flat_set &) = default; - flat_set &operator=(flat_set &&) = default; + flat_set &operator=(flat_set &&) noexcept = default; // Iterators. @@ -353,7 +353,7 @@ public: } // Free swap function for ADL. - friend void swap(flat_set &a, flat_set &b) { + friend void swap(flat_set &a, flat_set &b) noexcept { a.swap(b); } }; @@ -445,9 +445,9 @@ public: } flat_map(const flat_map &) = default; - flat_map(flat_map &&) = default; + flat_map(flat_map &&) noexcept = default; flat_map &operator=(const flat_map &) = default; - flat_map &operator=(flat_map &&) = default; + flat_map &operator=(flat_map &&) noexcept = default; // Iterators. @@ -637,7 +637,7 @@ public: } // Free swap function for ADL. - friend void swap(flat_map &a, flat_map &b) { + friend void swap(flat_map &a, flat_map &b) noexcept { a.swap(b); } }; diff --git a/src/util/insertion_ordered.h b/src/util/insertion_ordered.h index 8ba15dcd..0d36b124 100644 --- a/src/util/insertion_ordered.h +++ b/src/util/insertion_ordered.h @@ -178,7 +178,7 @@ public: return data < a.data; } - void swap(element_store &a) { + void swap(element_store &a) noexcept { using std::swap; swap(data, a.data); swap(map, a.map); @@ -278,11 +278,11 @@ public: return store < a.store; } - void swap(insertion_ordered_map &a) { + void swap(insertion_ordered_map &a) noexcept { store.swap(a.store); } - friend void swap(insertion_ordered_map &a, insertion_ordered_map &b) { + friend void swap(insertion_ordered_map &a, insertion_ordered_map &b) noexcept { a.swap(b); } }; @@ -355,11 +355,11 @@ public: return store < a.store; } - void swap(insertion_ordered_set &a) { + void swap(insertion_ordered_set &a) noexcept { store.swap(a.store); } - friend void swap(insertion_ordered_set &a, insertion_ordered_set &b) { + friend void swap(insertion_ordered_set &a, insertion_ordered_set &b) noexcept { a.swap(b); } }; diff --git a/src/util/ue2_graph.h b/src/util/ue2_graph.h index c3bf7755..c58bfd27 100644 --- a/src/util/ue2_graph.h +++ b/src/util/ue2_graph.h @@ -1003,7 +1003,7 @@ public: ue2_graph() = default; - ue2_graph(ue2_graph &&old) + ue2_graph(ue2_graph &&old) noexcept : next_vertex_index(old.next_vertex_index), next_edge_index(old.next_edge_index), graph_edge_count(old.graph_edge_count), @@ -1012,7 +1012,7 @@ public: swap(vertices_list, old.vertices_list); } - ue2_graph &operator=(ue2_graph &&old) { + ue2_graph &operator=(ue2_graph &&old) noexcept { next_vertex_index = old.next_vertex_index; next_edge_index = old.next_edge_index; graph_edge_count = old.graph_edge_count; diff --git a/src/util/ue2string.h b/src/util/ue2string.h index f436936d..dfa2d9e3 100644 --- a/src/util/ue2string.h +++ b/src/util/ue2string.h @@ -147,7 +147,7 @@ public: ue2_literal(const ue2_literal &) = default; ue2_literal(ue2_literal &&) = default; ue2_literal &operator=(const ue2_literal &) = default; - ue2_literal &operator=(ue2_literal &&) = default; + ue2_literal &operator=(ue2_literal &&) noexcept = default; template ue2_literal(InputIt b, InputIt e) { @@ -204,7 +204,7 @@ public: const std::string &get_string() const { return s; } - void swap(ue2_literal &other) { + void swap(ue2_literal &other) noexcept { s.swap(other.s); nocase.swap(other.nocase); } diff --git a/src/util/unicode_set.h b/src/util/unicode_set.h index e2dd351a..03f7efb3 100644 --- a/src/util/unicode_set.h +++ b/src/util/unicode_set.h @@ -130,7 +130,7 @@ public: return INVALID_UNICODE; } - void swap(CodePointSet &other) { impl.swap(other.impl); } + void swap(CodePointSet &other) noexcept { impl.swap(other.impl); } private: implT impl; diff --git a/tools/hsbench/huge.cpp b/tools/hsbench/huge.cpp index 331938df..66a20878 100644 --- a/tools/hsbench/huge.cpp +++ b/tools/hsbench/huge.cpp @@ -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; } diff --git a/tools/hscheck/main.cpp b/tools/hscheck/main.cpp index 918fe785..373ce388 100644 --- a/tools/hscheck/main.cpp +++ b/tools/hscheck/main.cpp @@ -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; } diff --git a/tools/hsdump/main.cpp b/tools/hsdump/main.cpp index 0364b93a..9ef33517 100644 --- a/tools/hsdump/main.cpp +++ b/tools/hsdump/main.cpp @@ -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)); diff --git a/unit/hyperscan/bad_patterns.cpp b/unit/hyperscan/bad_patterns.cpp index 42e4772e..750ccace 100644 --- a/unit/hyperscan/bad_patterns.cpp +++ b/unit/hyperscan/bad_patterns.cpp @@ -324,7 +324,7 @@ vector getBadPatterns() { string regex; hs_expr_ext ext; if (!readExpression(expr, regex, &flags, &ext)) { - cerr << expr << " failed in readExpression" << endl; + cerr << expr << " failed in readExpression\n"; abort(); } rv.push_back(BadPatternParam(regex, flags, ext, error)); diff --git a/unit/hyperscan/test_util.h b/unit/hyperscan/test_util.h index 01fdca0b..87a8f1aa 100644 --- a/unit/hyperscan/test_util.h +++ b/unit/hyperscan/test_util.h @@ -91,9 +91,9 @@ struct pattern { } pattern(std::string expression_in, unsigned int flags_in, - unsigned int id_in, hs_expr_ext ext_in) + unsigned int id_in,const hs_expr_ext& ext_in) : expression(std::move(expression_in)), flags(flags_in), id(id_in), - ext(std::move(ext_in)) {} + ext(ext_in) {} }; std::ostream &operator<<(std::ostream &o, const pattern &p); diff --git a/util/cross_compile.cpp b/util/cross_compile.cpp index 7431d55f..9f071905 100644 --- a/util/cross_compile.cpp +++ b/util/cross_compile.cpp @@ -55,7 +55,7 @@ unique_ptr xcompileReadMode(const char *s) { assert(!err); string str(s); - string opt = str.substr(str.find(":")+1, str.npos); + string opt = str.substr(str.find(':')+1, str.npos); bool found_mode = false; if (!opt.empty()) { diff --git a/util/database_util.cpp b/util/database_util.cpp index dbad7561..01c49d7b 100644 --- a/util/database_util.cpp +++ b/util/database_util.cpp @@ -96,7 +96,7 @@ hs_database_t * loadDatabase(const char *filename, bool verbose) { bytes = reinterpret_cast(mmap(nullptr, len, PROT_READ, MAP_SHARED, fd, 0)); if (bytes == MAP_FAILED) { - cout << "mmap failed" << endl; + cout << "mmap failed\n"; close(fd); return nullptr; } @@ -110,7 +110,7 @@ hs_database_t * loadDatabase(const char *filename, bool verbose) { is.seekg(0, ios::end); size_t len = is.tellg(); if (verbose) { - cout << "Reading " << len << " bytes" << endl; + cout << "Reading " << len << " bytes\n"; } is.seekg(0, ios::beg); bytes = new char[len]; @@ -130,7 +130,7 @@ hs_database_t * loadDatabase(const char *filename, bool verbose) { cout << "Serialized database info: " << info << endl; std::free(info); } else { - cout << "Unable to decode serialized database info." << endl; + cout << "Unable to decode serialized database info.\n"; } } diff --git a/util/expressions.cpp b/util/expressions.cpp index 74bf4ba2..e15cc2a1 100644 --- a/util/expressions.cpp +++ b/util/expressions.cpp @@ -53,7 +53,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); } @@ -137,7 +137,7 @@ void loadExpressions(const string &inPath, ExpressionMap &exprMap) { // Is our input path a file or a directory? struct stat st; if (stat(inPath.c_str(), &st) != 0) { - cerr << "Can't stat path: '" << inPath << "'" << endl; + cerr << "Can't stat path: '" << inPath << "'\n"; exit(1); } if (S_ISREG(st.st_mode)) { @@ -145,13 +145,13 @@ void loadExpressions(const string &inPath, ExpressionMap &exprMap) { try { loadExpressionsFromFile(inPath, exprMap); } catch (runtime_error &e) { - cerr << e.what() << ": '" << inPath << "'" << endl; + cerr << e.what() << ": '" << inPath << "'\n"; exit(1); } } else if (S_ISDIR(st.st_mode)) { DIR *d = opendir(inPath.c_str()); if (d == nullptr) { - cerr << "Can't open directory: '" << inPath << "'" << endl; + cerr << "Can't open directory: '" << inPath << "'\n"; exit(1); } for (struct dirent *ent = readdir(d); ent; ent = readdir(d)) { @@ -174,7 +174,7 @@ void loadExpressions(const string &inPath, ExpressionMap &exprMap) { try { loadExpressionsFromFile(fname, exprMap); } catch (runtime_error &e) { - cerr << e.what() << ": '" << fname << "'" << endl; + cerr << e.what() << ": '" << fname << "'\n"; exit(1); } } @@ -182,7 +182,7 @@ void loadExpressions(const string &inPath, ExpressionMap &exprMap) { } else { cerr << "Unsupported file type " << hex << showbase << (st.st_mode & S_IFMT) - << " for path: '" << inPath << "'" << endl; + << " for path: '" << inPath << "'\n"; exit(1); } } @@ -191,7 +191,7 @@ void HS_CDECL loadSignatureList(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); } @@ -223,7 +223,7 @@ ExpressionMap limitToSignatures(const ExpressionMap &exprMap, auto match = exprMap.find(id); if (match == exprMap.end()) { cerr << "Unable to find signature " << id - << " in expression set!" << endl; + << " in expression set!\n"; exit(1); } keepers.insert(*match); diff --git a/util/ng_corpus_generator.h b/util/ng_corpus_generator.h index cd84a9ab..0d73cedb 100644 --- a/util/ng_corpus_generator.h +++ b/util/ng_corpus_generator.h @@ -48,7 +48,7 @@ class NGHolder; struct CorpusGenerationFailure { explicit CorpusGenerationFailure(const std::string& s) : - message(std::move(s)) {} + message(s) {} std::string message; };