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:
parent
49354027a6
commit
adf2de8aed
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in a new issue