From 1f0e431259990c7601fc8815212f9aba437eb4f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Wed, 2 Jan 2019 15:36:02 -0800 Subject: [PATCH] Remove assert, add _ent_fail --- meson.build | 2 +- src/ent.c | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/meson.build b/meson.build index 174486e3c8..248096addc 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -project('libent', 'c', version: '0.1.1', license: 'MIT') +project('libent', 'c', version: '0.1.2', license: 'MIT') inc = include_directories('include') diff --git a/src/ent.c b/src/ent.c index c628f579b6..106cc25c31 100644 --- a/src/ent.c +++ b/src/ent.c @@ -14,7 +14,6 @@ } #elif defined(ENT_IMPL) -# include # include # if defined(ENT_GETRANDOM) # define _GNU_SOURCE @@ -35,19 +34,26 @@ # define ENT_FINI() (void) fclose(f) # endif + static int + _ent_fail() + { + errno = EIO; + return -1; + } + int ent_getentropy(void* buf, size_t len) { + int r; ENT_DEFS; - assert(len <= 256); + if (len > 256) + return _ent_fail(); ENT_INIT(); - if (len != ENT_READ(buf, len)) { - ENT_FINI(); - errno = EIO; - return -1; - } + r = ENT_READ(buf, len); ENT_FINI(); + if (r != len) + return _ent_fail(); return 0; }