Skip to content

Commit d648d57

Browse files
author
Daniel Kroening
authored
Merge pull request #493 from mgudemann/fix_shift_overflow_irep_hash_container
fix shift overflow in irep_hash_container
2 parents 509cf25 + 528fdbb commit d648d57

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/util/irep_hash_container.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Function: irep_hash_container_baset::number
2121
2222
\*******************************************************************/
2323

24-
unsigned irep_hash_container_baset::number(const irept &irep)
24+
size_t irep_hash_container_baset::number(const irept &irep)
2525
{
2626
// the ptr-hash provides a speedup of up to 3x
2727

@@ -32,7 +32,7 @@ unsigned irep_hash_container_baset::number(const irept &irep)
3232

3333
packedt packed;
3434
pack(irep, packed);
35-
unsigned id=numbering.number(packed);
35+
size_t id=numbering.number(packed);
3636

3737
ptr_hash[&irep.read()]=id;
3838

src/util/irep_hash_container.h

+12-10
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ Author: Daniel Kroening, [email protected]
1212
#include <cstdlib> // for size_t
1313
#include <vector>
1414

15+
#include "irep_hash.h"
1516
#include "numbering.h"
1617

1718
class irept;
1819

1920
class irep_hash_container_baset
2021
{
2122
public:
22-
unsigned number(const irept &irep);
23+
size_t number(const irept &irep);
2324

24-
irep_hash_container_baset(bool _full):full(_full)
25+
explicit irep_hash_container_baset(bool _full):full(_full)
2526
{
2627
}
2728

@@ -36,33 +37,34 @@ class irep_hash_container_baset
3637

3738
// this is the first level: address of the content
3839

39-
struct pointer_hash
40+
struct pointer_hasht
4041
{
4142
inline size_t operator()(const void *p) const
4243
{
4344
return (size_t)p;
4445
}
4546
};
4647

47-
typedef std::unordered_map<const void *, unsigned, pointer_hash> ptr_hasht;
48+
typedef std::unordered_map<const void *, size_t, pointer_hasht>
49+
ptr_hasht;
4850
ptr_hasht ptr_hash;
4951

5052
// this is the second level: content
5153

52-
typedef std::vector<unsigned> packedt;
54+
typedef std::vector<size_t> packedt;
5355

54-
struct vector_hash
56+
struct vector_hasht
5557
{
5658
inline size_t operator()(const packedt &p) const
5759
{
58-
size_t result=p.size();
59-
for(unsigned i=0; i<p.size(); i++)
60-
result^=p[i]<<i;
60+
size_t result=p.size(); // seed
61+
for(auto elem : p)
62+
result=hash_combine(result, elem);
6163
return result;
6264
}
6365
};
6466

65-
typedef hash_numbering<packedt, vector_hash> numberingt;
67+
typedef hash_numbering<packedt, vector_hasht> numberingt;
6668
numberingt numbering;
6769

6870
void pack(const irept &irep, packedt &);

0 commit comments

Comments
 (0)