Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH 1/1] zsh/random
On 8/31/2024 07:56, Oliver Kiddle wrote:
Clinton Bunch wrote:
I've made the recommended changes and removed the test file as the statistical
analysis proved to be flawed, and I can think of no other test.
Thanks. I've now applied the change. Thanks for being patient with us
and I'm sorry that reviews and feedback have dragged on.
My test build does now include the following message:
Including file Zsh/mod_random.yo
mod_random.yo:55: No macro: int(...)
I'm guessing it needs LPAR() and RPAR() where zrand_int is documented.
And with clang, I get a couple of new compiler warnings:
random.c:65:13: warning: variable 'val' set but not used [-Wunused-but-set-variable]
65 | size_t val = 0;
| ^
random.c:66:14: warning: variable 'bufptr' set but not used [-Wunused-but-set-variable]
66 | uint8_t *bufptr = buf;
| ^
This is probably conditional on HAVE_ARC4RANDOM_BUF being defined.
Oliver
Here's a patch for those issues.
diff --git a/Doc/Zsh/mod_random.yo b/Doc/Zsh/mod_random.yo
index d2892bf79..4f5622e61 100644
--- a/Doc/Zsh/mod_random.yo
+++ b/Doc/Zsh/mod_random.yo
@@ -41,7 +41,7 @@ tt(inclusive) is a flag that controls whether the
result is ever equal to
tt(upper). By default it is not. If this argument is set to a
non-zero value
then it may be.
-This is to facilitate a construct like tt($a[zrand_int($#a)+1]) rather
+This is to facilitate a construct like
tt($a[zrand_int+LPAR()$#a+RPAR()+1]) rather
than tt($a[zrand_int+LPAR()$#a-1+RPAR()+1]).
For example, if $#a is 16, you would use tt(zrand_int+LPAR()16RPAR())
which has
16 possible return values 0-15. Because the function can return zero,
in order
diff --git a/Src/Modules/random.c b/Src/Modules/random.c
index a153d8f64..88ac9543c 100644
--- a/Src/Modules/random.c
+++ b/Src/Modules/random.c
@@ -62,8 +62,10 @@ ssize_t
getrandom_buffer(void *buf, size_t len)
{
ssize_t ret;
+#ifndef HAVE_ARC4RANDOM_BUF
size_t val = 0;
uint8_t *bufptr = buf;
+#endif
do {
errno = 0;
@@ -81,8 +83,10 @@ getrandom_buffer(void *buf, size_t len)
return -1;
}
}
+#ifndef HAVE_ARC4RANDOM_BUF
bufptr += ret;
val += ret;
+#endif
} while (ret < len);
return ret;
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author