We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0180d0f commit b87d70dCopy full SHA for b87d70d
include/boost/json/detail/digest.hpp
@@ -32,15 +32,23 @@ digest(
32
#endif
33
hash += salt;
34
35
- char const* const end = s + n;
36
- for(;s < end;)
+ constexpr std::size_t step = sizeof(std::size_t);
+ auto const m = n - (n % step);
37
+ n -= m;
38
+
39
+ char const* const end = s + m;
40
+ for(; s < end; s += step)
41
{
- std::size_t step = (std::min)(sizeof(std::size_t),
- static_cast<std::size_t>(end - s));
- std::size_t batch = 0;
42
+ std::size_t batch;
43
std::memcpy(&batch, s, step);
44
hash = (batch ^ hash) * prime;
- s += step;
45
+ }
46
47
+ if(n)
48
+ {
49
+ std::size_t batch = 0;
50
+ std::memcpy(&batch, s, n);
51
+ hash = (batch ^ hash) * prime;
52
}
53
54
return hash;
0 commit comments