aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2016-11-15 20:17:39 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2016-11-15 20:17:39 +0000
commit27b3b3f4e68e584c6caa83088d87caa121d83796 (patch)
treef93eb9a075bea8a122905302101393b6f73732b3
parent3663671a13e12efe283d1b04df5416cedb796e86 (diff)
downloadgcc-27b3b3f4e68e584c6caa83088d87caa121d83796.zip
gcc-27b3b3f4e68e584c6caa83088d87caa121d83796.tar.gz
gcc-27b3b3f4e68e584c6caa83088d87caa121d83796.tar.bz2
PR 59406 note that FNV hash functions are incorrect
PR libstdc++/59406 * include/bits/functional_hash.h: Add comment noting difference from FNV-1a. * include/tr1/functional_hash.h: Likewise. * libsupc++/hash_bytes.cc: Likewise. From-SVN: r242454
-rw-r--r--libstdc++-v3/ChangeLog6
-rw-r--r--libstdc++-v3/include/bits/functional_hash.h1
-rw-r--r--libstdc++-v3/include/tr1/functional_hash.h4
-rw-r--r--libstdc++-v3/libsupc++/hash_bytes.cc6
4 files changed, 17 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 4bba6a4..d82aaa4 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,11 @@
2016-11-15 Jonathan Wakely <jwakely@redhat.com>
+ PR libstdc++/59406
+ * include/bits/functional_hash.h: Add comment noting difference from
+ FNV-1a.
+ * include/tr1/functional_hash.h: Likewise.
+ * libsupc++/hash_bytes.cc: Likewise.
+
* include/bits/basic_string.h: Reuse _If_sv alias template for new
constructor.
diff --git a/libstdc++-v3/include/bits/functional_hash.h b/libstdc++-v3/include/bits/functional_hash.h
index dc09683..cee1ea8 100644
--- a/libstdc++-v3/include/bits/functional_hash.h
+++ b/libstdc++-v3/include/bits/functional_hash.h
@@ -200,6 +200,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return hash(&__val, sizeof(__val), __hash); }
};
+ // A hash function similar to FNV-1a (see PR59406 for how it differs).
struct _Fnv_hash_impl
{
static size_t
diff --git a/libstdc++-v3/include/tr1/functional_hash.h b/libstdc++-v3/include/tr1/functional_hash.h
index 4edc49a..8148e4d 100644
--- a/libstdc++-v3/include/tr1/functional_hash.h
+++ b/libstdc++-v3/include/tr1/functional_hash.h
@@ -83,6 +83,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Fowler / Noll / Vo (FNV) Hash (type FNV-1a)
// (Used by the next specializations of std::tr1::hash.)
+ // N.B. These functions should work on unsigned char, otherwise they do not
+ // correctly implement the FNV-1a algorithm (see PR59406).
+ // The existing behaviour is retained for backwards compatibility.
+
/// Dummy generic implementation (for sizeof(size_t) != 4, 8).
template<size_t>
struct _Fnv_hash_base
diff --git a/libstdc++-v3/libsupc++/hash_bytes.cc b/libstdc++-v3/libsupc++/hash_bytes.cc
index 1042de6..7d76c34 100644
--- a/libstdc++-v3/libsupc++/hash_bytes.cc
+++ b/libstdc++-v3/libsupc++/hash_bytes.cc
@@ -112,6 +112,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
// Implementation of FNV hash for 32-bit size_t.
+ // N.B. This function should work on unsigned char, otherwise it does not
+ // correctly implement the FNV-1a algorithm (see PR59406).
+ // The existing behaviour is retained for backwards compatibility.
size_t
_Fnv_hash_bytes(const void* ptr, size_t len, size_t hash)
{
@@ -157,6 +160,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
// Implementation of FNV hash for 64-bit size_t.
+ // N.B. This function should work on unsigned char, otherwise it does not
+ // correctly implement the FNV-1a algorithm (see PR59406).
+ // The existing behaviour is retained for backwards compatibility.
size_t
_Fnv_hash_bytes(const void* ptr, size_t len, size_t hash)
{