summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/random.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/random.c b/src/random.c
index 2f9f731..2b41645 100644
--- a/src/random.c
+++ b/src/random.c
@@ -12,18 +12,15 @@
#include "random.h"
-/// A temporary buffer is used to avoid writing to `addr` while having an error
-/// when calling `fclose(3)`;
int
urandom_bytes(const size_t n, uint8_t (*const addr)[]) {
int rc = -1;
- // FIXME: rename ret
- uint8_t *temp = NULL;
+ uint8_t *ret = NULL;
FILE *f = NULL;
- temp = malloc(n);
- if (temp == NULL) {
+ ret = malloc(n);
+ if (ret == NULL) {
logerr("malloc(): %s", strerror(errno));
goto out;
}
@@ -34,7 +31,7 @@ urandom_bytes(const size_t n, uint8_t (*const addr)[]) {
goto out;
}
- const size_t read_count = fread(temp, 1, n, f);
+ const size_t read_count = fread(ret, 1, n, f);
if (ferror(f)) {
logerr("fread(): %s", strerror(errno));
goto out;
@@ -47,7 +44,7 @@ urandom_bytes(const size_t n, uint8_t (*const addr)[]) {
}
f = NULL;
- memcpy(addr, temp, n);
+ memcpy(addr, ret, n);
rc = 0;
out:
if (f != NULL) {
@@ -56,8 +53,8 @@ out:
rc = -1;
}
}
- if (temp != NULL) {
- free(temp);
+ if (ret != NULL) {
+ free(ret);
}
return rc;
}