From 2500778920f533c56fa55798ec8d381276ae84d1 Mon Sep 17 00:00:00 2001 From: Kerin Millar Date: Wed, 7 Aug 2024 18:45:02 +0100 Subject: Have srandom() employ an upper bound of 2^31-1 In the case of some shells - mksh, at least - the maximum value of an integer is 2147483647. Such is a consequence of implementing integers as signed int rather than signed long, even though doing so contravenes the specification. Reduce the output range of srandom() so as to be between 0 and 2147483647, rather than 0 and 4294967295. A change of this scope would normally justify incrementing GENFUN_API_LEVEL but I shall not do so on this occasion. My rationale is that >=gentoo-functions-1.7 has not yet had enough exposure for srandom() to be in use by other projects. Additionally, have test-functions test srandom() 10 times instead of 5. Signed-off-by: Kerin Millar Signed-off-by: Sam James --- test-functions | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'test-functions') diff --git a/test-functions b/test-functions index 4b2f7f9..96781f2 100755 --- a/test-functions +++ b/test-functions @@ -415,21 +415,25 @@ test_yesno() { test_srandom() { set -- \ + eq 0 \ + eq 0 \ + eq 0 \ + eq 0 \ + eq 0 \ eq 0 \ eq 0 \ eq 0 \ eq 0 \ eq 0 - row=0 - callback() { number=$(srandom) - test_description="srandom ($(( row += 1 ))/5: ${number:-blank})" + test_description="srandom ($(( row += 1 ))/10: ${number:-blank})" is_int "${number}" \ - && awk -v "n=${number}" 'BEGIN { exit !(n >= 0 && n <= 4294967295) }' + && awk -v "n=${number}" 'BEGIN { exit !(n >= 0 && n <= 2147483647) }' } + row=0 iterate_tests 2 "$@" } -- cgit v1.2.3-65-gdbad