Skip to content

Commit cf6f008

Browse files
authored
Merge pull request #1206 from AntelopeIO/gh_1185
Fix poor hash function for `chain::name`
2 parents 22834d5 + a4c8289 commit cf6f008

File tree

1 file changed

+5
-3
lines changed
  • libraries/chain/include/eosio/chain

1 file changed

+5
-3
lines changed

libraries/chain/include/eosio/chain/name.hpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <string>
33
#include <fc/reflect/reflect.hpp>
44
#include <iosfwd>
5+
#include <byteswap.h>
56

67
namespace eosio::chain {
78
struct name;
@@ -179,9 +180,10 @@ namespace eosio::chain {
179180
namespace std {
180181
template<> struct hash<eosio::chain::name> : private hash<uint64_t> {
181182
typedef eosio::chain::name argument_type;
182-
size_t operator()(const argument_type& name) const noexcept
183-
{
184-
return hash<uint64_t>::operator()(name.to_uint64_t());
183+
184+
size_t operator()(const argument_type& name) const noexcept {
185+
static_assert(sizeof(size_t) == sizeof(uint64_t));
186+
return bswap_64(name.to_uint64_t());
185187
}
186188
};
187189
};

0 commit comments

Comments
 (0)