PP(pp_srand)
{
dVAR; dSP; dTARGET;
- const UV anum = (MAXARG < 1 || (!TOPs && !POPs)) ? seed() : POPu;
+ UV anum;
+
+ if (MAXARG >= 1 && TOPs) {
+ SV *top;
+ char *pv;
+ STRLEN len;
+ int flags;
+
+ top = POPs;
+ pv = SvPV(top, len);
+ flags = grok_number(pv, len, &anum);
+
+ if (!(flags & IS_NUMBER_IN_UV)) {
+ Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW),
+ "Integer overflow in srand");
+ anum = UV_MAX;
+ }
+ }
+ else {
+ anum = seed();
+ }
+
(void)seedDrand01((Rand_seed_t)anum);
PL_srand_called = TRUE;
if (anum)
use strict;
require "test.pl";
-plan(tests => 9);
+plan(tests => 10);
# Generate a load of random numbers.
# int() avoids possible floating point error.
is( $b, 0, "Quacks like a zero");
is( "@warnings", "", "Does not warn");
}
+
+# [perl #40605]
+{
+ use warnings;
+ my $w = '';
+ local $SIG{__WARN__} = sub { $w .= $_[0] };
+ srand(2**100);
+ like($w, qr/^Integer overflow in srand at /, "got a warning");
+}