mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Fix a number of Coverity issues in Dict
1431186: Asserting that an unsigned value is >= 0 is pointless 1431188/1431189/1431191: Side effect of using an assignment operator in a call to ASSERT() 1431193: Dereference after null check could lead to null being used 1431195: Use of rand() replaced with random()
This commit is contained in:
parent
5816ea27e9
commit
ce98666621
1 changed files with 22 additions and 12 deletions
34
src/Dict.cc
34
src/Dict.cc
|
@ -283,7 +283,7 @@ int Dictionary::BucketByHash(zeek::detail::hash_t h, int log2_table_size) const
|
|||
int m = 64 - log2_table_size;
|
||||
hash <<= m;
|
||||
hash >>= m;
|
||||
ASSERT(hash>=0);
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
@ -368,36 +368,44 @@ void Dictionary::AssertValid() const
|
|||
{
|
||||
bool valid = true;
|
||||
int n = num_entries;
|
||||
for ( int i = Capacity()-1; i >= 0; i-- )
|
||||
if ( table && ! table[i].Empty() )
|
||||
n--;
|
||||
|
||||
ASSERT((valid = (n==0)));
|
||||
if ( table )
|
||||
for ( int i = Capacity()-1; i >= 0; i-- )
|
||||
if ( ! table[i].Empty() )
|
||||
n--;
|
||||
|
||||
valid = (n == 0);
|
||||
ASSERT(valid);
|
||||
DUMPIF(! valid);
|
||||
|
||||
//entries must clustered together
|
||||
for ( int i = 1; i < Capacity(); i++ )
|
||||
{
|
||||
if ( table[i].Empty() )
|
||||
if ( ! table || table[i].Empty() )
|
||||
continue;
|
||||
|
||||
if ( table[i-1].Empty() )
|
||||
{
|
||||
ASSERT((valid=(table[i].distance == 0)));
|
||||
valid = (table[i].distance == 0);
|
||||
ASSERT(valid);
|
||||
DUMPIF(! valid);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT((valid=(table[i].bucket >= table[i-1].bucket)));
|
||||
valid = (table[i].bucket >= table[i-1].bucket);
|
||||
ASSERT(valid);
|
||||
DUMPIF(! valid);
|
||||
|
||||
if ( table[i].bucket == table[i-1].bucket )
|
||||
{
|
||||
ASSERT((valid=(table[i].distance == table[i-1].distance+1)));
|
||||
valid = (table[i].distance == table[i-1].distance+1);
|
||||
ASSERT(valid);
|
||||
DUMPIF(! valid);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT((valid=(table[i].distance <= table[i-1].distance)));
|
||||
valid = (table[i].distance <= table[i-1].distance);
|
||||
ASSERT(valid);
|
||||
DUMPIF(! valid);
|
||||
}
|
||||
}
|
||||
|
@ -446,7 +454,8 @@ void Dictionary::DumpKeys() const
|
|||
DistanceStats(max_distance);
|
||||
if ( binary )
|
||||
{
|
||||
sprintf(key_file, "%d.%d.%zu-%c.key", Length(), max_distance, MemoryAllocation()/Length(), rand()%26 + 'A');
|
||||
char key = char(random() % 26) + 'A';
|
||||
sprintf(key_file, "%d.%d.%zu-%c.key", Length(), max_distance, MemoryAllocation()/Length(), key);
|
||||
std::ofstream f(key_file, std::ios::binary|std::ios::out|std::ios::trunc);
|
||||
for ( int idx = 0; idx < Capacity(); idx++ )
|
||||
if ( ! table[idx].Empty() )
|
||||
|
@ -458,7 +467,8 @@ void Dictionary::DumpKeys() const
|
|||
}
|
||||
else
|
||||
{
|
||||
sprintf(key_file, "%d.%d.%zu-%d.ckey",Length(), max_distance, MemoryAllocation()/Length(), rand()%26 + 'A');
|
||||
char key = char(random() % 26) + 'A';
|
||||
sprintf(key_file, "%d.%d.%zu-%d.ckey",Length(), max_distance, MemoryAllocation()/Length(), key);
|
||||
std::ofstream f(key_file, std::ios::out|std::ios::trunc);
|
||||
for ( int idx = 0; idx < Capacity(); idx++ )
|
||||
if ( ! table[idx].Empty() )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue