[libvirt] [PATCH 02/10] virCryptoGenerateRandom: rename ret

Michal Privoznik posted 10 patches 6 years, 11 months ago
[libvirt] [PATCH 02/10] virCryptoGenerateRandom: rename ret
Posted by Michal Privoznik 6 years, 11 months ago
This function allocates a buffer, fills it in with random bytes
and then returns it. However, the buffer is held in @buf
variable, therefore having @ret variable which does not hold
return value of the function is misleading.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/util/vircrypto.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/util/vircrypto.c b/src/util/vircrypto.c
index 4079013d6d..930fa3b215 100644
--- a/src/util/vircrypto.c
+++ b/src/util/vircrypto.c
@@ -329,16 +329,16 @@ uint8_t *
 virCryptoGenerateRandom(size_t nbytes)
 {
     uint8_t *buf;
-    int ret;
+    int rv;
 
     if (VIR_ALLOC_N(buf, nbytes) < 0)
         return NULL;
 
 #if WITH_GNUTLS
     /* Generate the byte stream using gnutls_rnd() if possible */
-    if ((ret = gnutls_rnd(GNUTLS_RND_RANDOM, buf, nbytes)) < 0) {
+    if ((rv = gnutls_rnd(GNUTLS_RND_RANDOM, buf, nbytes)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("failed to generate byte stream, ret=%d"), ret);
+                       _("failed to generate byte stream, rv=%d"), rv);
         VIR_FREE(buf);
         return NULL;
     }
@@ -346,8 +346,8 @@ virCryptoGenerateRandom(size_t nbytes)
     /* If we don't have gnutls_rnd(), we will generate a less cryptographically
      * strong master buf from /dev/urandom.
      */
-    if ((ret = virRandomBytes(buf, nbytes)) < 0) {
-        virReportSystemError(-ret, "%s", _("failed to generate byte stream"));
+    if ((rv = virRandomBytes(buf, nbytes)) < 0) {
+        virReportSystemError(-rv, "%s", _("failed to generate byte stream"));
         VIR_FREE(buf);
         return NULL;
     }
-- 
2.16.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 02/10] virCryptoGenerateRandom: rename ret
Posted by Eric Blake 6 years, 11 months ago
On 05/29/2018 03:24 AM, Michal Privoznik wrote:
> This function allocates a buffer, fills it in with random bytes
> and then returns it. However, the buffer is held in @buf
> variable, therefore having @ret variable which does not hold
> return value of the function is misleading.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>   src/util/vircrypto.c | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list