Fix clang-tidy bugprone-suspicious-string-compare warnings

This commit is contained in:
Tim Wojtulewicz 2025-04-17 13:22:35 -07:00
parent 975f24bde6
commit 4d60d4833e
7 changed files with 8 additions and 7 deletions

View file

@ -11,4 +11,5 @@ Checks: [-*,
bugprone-parent-virtual-call, bugprone-parent-virtual-call,
bugprone-string-literal-with-embedded-nul, bugprone-string-literal-with-embedded-nul,
bugprone-suspicious-stringview-data-usage, bugprone-suspicious-stringview-data-usage,
bugprone-suspicious-string-compare,
] ]

View file

@ -147,7 +147,7 @@ int find_all_matching_cmds(const string& prefix, const char* array_of_matches[])
for ( int j = 0; j < g_DebugCmdInfos[i]->NumNames(); ++j ) { for ( int j = 0; j < g_DebugCmdInfos[i]->NumNames(); ++j ) {
const char* curr_name = g_DebugCmdInfos[i]->Names()[j]; const char* curr_name = g_DebugCmdInfos[i]->Names()[j];
if ( strncmp(curr_name, prefix.c_str(), arglen) ) if ( strncmp(curr_name, prefix.c_str(), arglen) != 0 )
continue; continue;
// If exact match, then only return that one. // If exact match, then only return that one.

View file

@ -158,7 +158,7 @@ void FragReassembler::Weird(const char* name) const {
} }
void FragReassembler::Overlap(const u_char* b1, const u_char* b2, uint64_t n) { void FragReassembler::Overlap(const u_char* b1, const u_char* b2, uint64_t n) {
if ( memcmp((const void*)b1, (const void*)b2, n) ) if ( memcmp((const void*)b1, (const void*)b2, n) != 0 )
Weird("fragment_inconsistency"); Weird("fragment_inconsistency");
else else
Weird("fragment_overlap"); Weird("fragment_overlap");

View file

@ -38,7 +38,7 @@ flow BitTorrent_Flow(is_orig: bool) {
function validate_handshake(pstrlen: uint8, pstr: const_bytestring): bool function validate_handshake(pstrlen: uint8, pstr: const_bytestring): bool
%{ %{
if ( pstrlen != 19 || if ( pstrlen != 19 ||
memcmp("BitTorrent protocol", pstr.begin(), 19) ) memcmp("BitTorrent protocol", pstr.begin(), 19) != 0 )
{ {
throw Exception("invalid handshake"); throw Exception("invalid handshake");
} }

View file

@ -117,11 +117,11 @@ bool Gnutella_Analyzer::IsHTTP(std::string header) {
} }
bool Gnutella_Analyzer::GnutellaOK(std::string header) { bool Gnutella_Analyzer::GnutellaOK(std::string header) {
if ( strncmp("GNUTELLA", header.data(), 8) ) if ( strncmp("GNUTELLA", header.data(), 8) != 0 )
return false; return false;
int codepos = header.find(' ') + 1; int codepos = header.find(' ') + 1;
if ( ! strncmp("200", header.data() + codepos, 3) ) if ( strncmp("200", header.data() + codepos, 3) == 0 )
return true; return true;
return false; return false;

View file

@ -396,7 +396,7 @@ void TCP_Reassembler::Overlap(const u_char* b1, const u_char* b2, uint64_t n) {
if ( DEBUG_tcp_contents ) if ( DEBUG_tcp_contents )
DEBUG_MSG("%.6f TCP contents overlap: %" PRIu64 " IsOrig()=%d\n", run_state::network_time, n, IsOrig()); DEBUG_MSG("%.6f TCP contents overlap: %" PRIu64 " IsOrig()=%d\n", run_state::network_time, n, IsOrig());
if ( rexmit_inconsistency && memcmp((const void*)b1, (const void*)b2, n) && if ( rexmit_inconsistency && (memcmp((const void*)b1, (const void*)b2, n) != 0) &&
// The following weeds out keep-alives for which that's all // The following weeds out keep-alives for which that's all
// we've ever seen for the connection. // we've ever seen for the connection.
(n > 1 || endp->peer->HasDoneSomething()) ) { (n > 1 || endp->peer->HasDoneSomething()) ) {

View file

@ -346,7 +346,7 @@ void PackageTarget::DoFindDependencies(const vector<Info*>& infos) {
continue; continue;
for ( size_t j = 0; j < pkg_deps.size(); ++j ) { for ( size_t j = 0; j < pkg_deps.size(); ++j ) {
if ( strncmp(script->Name().c_str(), pkg_deps[j]->Name().c_str(), pkg_deps[j]->Name().size()) ) if ( strncmp(script->Name().c_str(), pkg_deps[j]->Name().c_str(), pkg_deps[j]->Name().size()) != 0 )
continue; continue;
DBG_LOG(DBG_ZEEKYGEN, "Script %s associated with package %s", script->Name().c_str(), DBG_LOG(DBG_ZEEKYGEN, "Script %s associated with package %s", script->Name().c_str(),