From 33e11b79e44bb57dbfbe002aa99140b172cba614 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sat, 29 Dec 2012 11:11:43 +0000 Subject: [PATCH] Hash: Merge UB fix to release. [SVN r82256] --- hash/doc/changes.qbk | 1 + include/boost/functional/hash/detail/hash_float.hpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/hash/doc/changes.qbk b/hash/doc/changes.qbk index b20e58d..2a37d5d 100644 --- a/hash/doc/changes.qbk +++ b/hash/doc/changes.qbk @@ -150,5 +150,6 @@ * On platforms that are known to have standard floating point, don't use the automatic detection of floating point functions - which can break if there are ambiguous overloads. +* Fix undefined behaviour when using the binary float hash (Thomas Heller). [endsect] diff --git a/include/boost/functional/hash/detail/hash_float.hpp b/include/boost/functional/hash/detail/hash_float.hpp index 5e20b9c..a98cd70 100644 --- a/include/boost/functional/hash/detail/hash_float.hpp +++ b/include/boost/functional/hash/detail/hash_float.hpp @@ -73,7 +73,9 @@ namespace boost ptr += sizeof(std::size_t); while(length >= sizeof(std::size_t)) { - hash_float_combine(seed, *(std::size_t*) ptr); + std::size_t buffer = 0; + std::memcpy(&buffer, ptr, sizeof(std::size_t)); + hash_float_combine(seed, buffer); length -= sizeof(std::size_t); ptr += sizeof(std::size_t); }