Fix clang-tidy bugprone-implicit-widening-of-multiplication-result warnings

This commit is contained in:
Tim Wojtulewicz 2025-04-16 12:23:40 -07:00
parent bdb0fad6d5
commit 18983aed02
6 changed files with 10 additions and 9 deletions

View file

@ -1,4 +1,5 @@
Checks: [-*,
bugprone-assignment-in-if-condition,
bugprone-branch-clone,
bugprone-implicit-widening-of-multiplication-result,
]

View file

@ -187,9 +187,9 @@ public:
SWNode* operator()(int row, int col) {
// Make sure access is in allowed range.
if ( row < 0 || row >= _rows )
if ( row < 0 || static_cast<size_t>(row) >= _rows )
return nullptr;
if ( col < 0 || col >= _cols )
if ( col < 0 || static_cast<size_t>(col) >= _cols )
return nullptr;
return &(_nodes[row * _cols + col]);
@ -215,7 +215,7 @@ private:
const String* _s1;
const String* _s2;
int _rows, _cols;
size_t _rows, _cols;
SWNode* _nodes;
};

View file

@ -9,7 +9,7 @@
namespace zeek {
constexpr int UID_LEN = 2;
constexpr size_t UID_LEN = 2;
/**
* A class for creating/managing UIDs of arbitrary bit-length and converting

View file

@ -128,8 +128,8 @@ double X509Common::GetTimeFromAsn1(const ASN1_TIME* atime, file_analysis::File*
return 0;
}
lSecondsFromUTC = ((pString[1] - '0') * 10 + (pString[2] - '0')) * 60;
lSecondsFromUTC += (pString[3] - '0') * 10 + (pString[4] - '0');
lSecondsFromUTC = static_cast<time_t>((pString[1] - '0') * 10) + static_cast<time_t>((pString[2] - '0') * 60);
lSecondsFromUTC += static_cast<time_t>((pString[3] - '0') * 10) + (pString[4] - '0');
if ( *pString == '-' )
lSecondsFromUTC = -lSecondsFromUTC;

View file

@ -60,7 +60,7 @@ ARPAnalyzer::ARPAnalyzer() : zeek::packet_analysis::Analyzer("ARP") {}
#endif
#ifndef ar_tpa
#define ar_tpa(ap) ((caddr_t((ap) + 1)) + 2 * (ap)->ar_hln + (ap)->ar_pln)
#define ar_tpa(ap) ((caddr_t((ap) + 1)) + 2 * static_cast<size_t>((ap)->ar_hln) + (ap)->ar_pln)
#endif
#ifndef ARPOP_REVREQUEST

View file

@ -299,7 +299,7 @@ static zeek::RecordValPtr build_syn_packet_val(bool is_orig, const zeek::IP_Hdr*
// Parse TCP options.
u_char* options = (u_char*)tcp + sizeof(struct tcphdr);
u_char* opt_end = (u_char*)tcp + tcp->th_off * 4;
u_char* opt_end = (u_char*)tcp + static_cast<ptrdiff_t>(tcp->th_off * 4);
while ( options < opt_end ) {
unsigned int opt = options[0];
@ -1462,7 +1462,7 @@ void TCPSessionAdapter::SynWeirds(analyzer::tcp::TCP_Flags flags, analyzer::tcp:
int TCPSessionAdapter::ParseTCPOptions(const struct tcphdr* tcp, bool is_orig) {
// Parse TCP options.
const u_char* options = (const u_char*)tcp + sizeof(struct tcphdr);
const u_char* opt_end = (const u_char*)tcp + tcp->th_off * 4;
const u_char* opt_end = (const u_char*)tcp + static_cast<ptrdiff_t>(tcp->th_off * 4);
std::vector<const u_char*> opts;
while ( options < opt_end ) {