summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKerin Millar <kfm@plushkava.net>2024-08-07 18:45:02 +0100
committerSam James <sam@gentoo.org>2024-08-11 11:10:57 +0100
commit2500778920f533c56fa55798ec8d381276ae84d1 (patch)
treeb7596fe43d711ecc1f3aa0a5f1fd245964c17d6f /test-functions
parenttest-functions: check numerical bounds with awk in test_srandom() (diff)
downloadgentoo-functions-2500778920f533c56fa55798ec8d381276ae84d1.tar.gz
gentoo-functions-2500778920f533c56fa55798ec8d381276ae84d1.tar.bz2
gentoo-functions-2500778920f533c56fa55798ec8d381276ae84d1.zip
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 <kfm@plushkava.net> Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'test-functions')
-rwxr-xr-xtest-functions12
1 files changed, 8 insertions, 4 deletions
diff --git a/test-functions b/test-functions
index 4b2f7f9..96781f2 100755
--- a/test-functions
+++ b/test-functions
@@ -419,17 +419,21 @@ test_srandom() {
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 "$@"
}