A bunch of other minor issues reported by PVS-Studio

This commit is contained in:
Tim Wojtulewicz 2023-01-14 16:35:49 -07:00
parent 53f2364a86
commit 35ee96c4cb
7 changed files with 15 additions and 11 deletions

View file

@ -645,7 +645,7 @@ public:
auto loc = detail::GetCurrentLocation();
reporter->RuntimeError(&loc,
"Attempted to create DictEntry with excessively large key, "
"truncating key (%" PRIu64 " > %d)",
"truncating key (%" PRIu64 " > %u)",
key_size, detail::DictEntry<T>::MAX_KEY_SIZE);
}

View file

@ -79,7 +79,6 @@ void RandTest::add(const void* buf, int bufl)
if ( sccfirst )
{
sccfirst = 0;
scclast = 0;
sccu0 = oc;
}
else
@ -98,17 +97,15 @@ void RandTest::end(double* r_ent, double* r_chisq, double* r_mean, double* r_mon
double* r_scc)
{
int i;
double ent, chisq, scc, datasum;
ent = 0.0;
chisq = 0.0;
scc = 0.0;
datasum = 0.0;
double ent = 0.0;
double chisq = 0.0;
double datasum = 0.0;
double prob[256]; /* Probabilities per bin for entropy */
/* Complete calculation of serial correlation coefficient */
scct1 = scct1 + scclast * sccu0;
scct2 = scct2 * scct2;
scc = totalc * scct3 - scct2;
double scc = totalc * scct3 - scct2;
if ( scc == 0.0 )
scc = -100000;
else

View file

@ -77,6 +77,9 @@ void String::Reset()
const String& String::operator=(const String& bs)
{
if ( this == &bs )
return *this;
Reset();
n = bs.n;
b = new u_char[n + 1];

View file

@ -630,7 +630,7 @@ Plugin* Manager::LookupPluginByPath(std::string_view _path)
static bool hook_cmp(std::pair<int, Plugin*> a, std::pair<int, Plugin*> b)
{
if ( a.first == b.first )
return util::strtolower(a.second->Name()) < util::strtolower(a.second->Name());
return util::strtolower(a.second->Name()) < util::strtolower(b.second->Name());
// Reverse sort.
return a.first > b.first;

View file

@ -70,6 +70,10 @@ std::unique_ptr<BloomFilter> BloomFilter::Unserialize(const broker::data& data)
case Counting:
bf = std::unique_ptr<BloomFilter>(new CountingBloomFilter());
break;
default:
reporter->Error("found invalid bloom filter type");
return nullptr;
}
if ( ! bf->DoUnserialize((*v)[2]) )

View file

@ -158,7 +158,7 @@ double CardinalityCounter::Size() const
answer = 1 / answer;
answer = (alpha_m * m * m * answer);
if ( answer <= 5.0 * (m / 2) )
if ( answer <= 5.0 * (((double)m) / 2) )
return m * log(((double)m) / V);
else if ( answer <= (pow(2, 64) / 30) )

View file

@ -349,7 +349,7 @@ static bool read_random_seeds(const char* read_file, uint32_t* seed,
// Read seeds for hmac-md5/siphash/highwayhash.
for ( auto& v : buf )
{
int tmp;
uint32_t tmp;
if ( fscanf(f, "%u", &tmp) != 1 )
{
fclose(f);