0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd::buffer: Add include-conditioned zero() fallback and improve return semantic.

This commit is contained in:
Jason Volk 2018-11-16 14:13:34 -08:00
parent 49354027a6
commit adf2de8aed
2 changed files with 14 additions and 2 deletions

View file

@ -75,7 +75,7 @@ namespace ircd::buffer
size_t move(const mutable_buffer &dst, const const_buffer &src);
size_t reverse(const mutable_buffer &dst, const const_buffer &src);
void reverse(const mutable_buffer &buf);
void zero(const mutable_buffer &buf);
size_t zero(const mutable_buffer &buf);
// Convenience copy to std stream
template<class it> std::ostream &operator<<(std::ostream &s, const buffer<it> &buffer);
@ -208,6 +208,17 @@ ircd::buffer::operator<<(std::ostream &s, const buffer<it> &buffer)
return s;
}
// We use the sodium_memzero() from libsodium in ircd/sodium.cc if available
// to ensure cross-platform guarantees the zero'ing doesn't get optimized away.
#ifndef HAVE_SODIUM_H
inline size_t
ircd::buffer::zero(const mutable_buffer &buf)
{
std::memset(data(buf), 0x0, size(buf));
return size(buf);
}
#endif
inline void
ircd::buffer::reverse(const mutable_buffer &buf)
{

View file

@ -51,10 +51,11 @@ noexcept
// ircd/buffer.h
//
void
size_t
ircd::buffer::zero(const mutable_buffer &buf)
{
sodium_memzero(data(buf), size(buf));
return size(buf);
}
///////////////////////////////////////////////////////////////////////////////