diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-06-24 03:10:05 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2012-06-24 03:13:53 -0500 |
commit | f914a68295eedf2aa19e258317bc5955132805b4 (patch) | |
tree | f3c34454cbe603d8467fd4f7f9690ae759b056b0 /pp.c | |
parent | c6cec3077440d7e149a8013d9939e2f5626ce21a (diff) | |
download | perl-f914a68295eedf2aa19e258317bc5955132805b4.tar.gz |
warn when srand overflows [perl #40605]
Diffstat (limited to 'pp.c')
-rw-r--r-- | pp.c | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -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) |