diff options
author | EuAndreh <eu@euandre.org> | 2024-05-24 21:36:45 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-05-24 21:36:48 -0300 |
commit | f9806b650bd3d17adfab89a0ded88f1379461b34 (patch) | |
tree | dbc6adb38455656e77024641d14c2adfe06df2d4 | |
parent | tests/vector.c: Add most missing tests (diff) | |
download | pindaiba-f9806b650bd3d17adfab89a0ded88f1379461b34.tar.gz pindaiba-f9806b650bd3d17adfab89a0ded88f1379461b34.tar.xz |
src/random.c: Simplify via better variable names
-rw-r--r-- | src/random.c | 17 |
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; } |