Support randombytes() with size == 0, but don't force implementations to support it

This commit is contained in:
Frank Denis 2013-11-21 23:22:45 -08:00
parent b64f19d439
commit 08755e04e1
3 changed files with 5 additions and 1 deletions

View File

@ -46,7 +46,9 @@ randombytes_uniform(const uint32_t upper_bound)
void
randombytes_buf(void * const buf, const size_t size)
{
implementation->buf(buf, size);
if (size > (size_t) 0U) {
implementation->buf(buf, size);
}
}
int

View File

@ -85,6 +85,7 @@ safe_read(const int fd, void * const buf_, size_t count)
unsigned char *buf = (unsigned char *) buf_;
ssize_t readnb;
assert(count > (size_t) 0U);
do {
while ((readnb = read(fd, buf, count)) < (ssize_t) 0 &&
errno == EINTR);

View File

@ -45,6 +45,7 @@ safe_read(const int fd, void * const buf_, size_t count)
unsigned char *buf = (unsigned char *) buf_;
ssize_t readnb;
assert(count > (size_t) 0U);
do {
while ((readnb = read(fd, buf, count)) < (ssize_t) 0 &&
errno == EINTR);