summaryrefslogtreecommitdiff
path: root/pp.c
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-06-24 03:10:05 -0500
committerJesse Luehrs <doy@tozt.net>2012-06-24 03:13:53 -0500
commitf914a68295eedf2aa19e258317bc5955132805b4 (patch)
treef3c34454cbe603d8467fd4f7f9690ae759b056b0 /pp.c
parentc6cec3077440d7e149a8013d9939e2f5626ce21a (diff)
downloadperl-f914a68295eedf2aa19e258317bc5955132805b4.tar.gz
warn when srand overflows [perl #40605]
Diffstat (limited to 'pp.c')
-rw-r--r--pp.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/pp.c b/pp.c
index d44b4eea05..6936b4f796 100644
--- a/pp.c
+++ b/pp.c
@@ -2658,7 +2658,28 @@ PP(pp_rand)
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)