diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2015-06-22 06:50:34 -0400 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2015-06-26 23:09:39 -0400 |
commit | 393bc9b3483a2e80d10a63fec99c2b2088b66154 (patch) | |
tree | 0365b9a64c3cf674f800b774e69407070db3b388 /pp_sys.c | |
parent | add0dc910759dea695e812146f825ac72b8cd089 (diff) | |
download | perl-393bc9b3483a2e80d10a63fec99c2b2088b66154.tar.gz |
sleep() with negative argument makes no sense.
Give by default a warning, do not sleep, and return zero.
(the signedness problem detected by Coverity, CID 104844)
Other options would include not giving a warning at all,
giving a warning only if asked, and finally croaking.
(Python had this problem earlier, and chose croaking.)
Earlier discussion in
http://www.nntp.perl.org/group/perl.perl5.porters/2015/03/msg226304.html
See also:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html
http://linux.die.net/man/3/sleep
https://www.freebsd.org/cgi/man.cgi?query=sleep&sektion=3
Diffstat (limited to 'pp_sys.c')
-rw-r--r-- | pp_sys.c | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -4749,7 +4749,16 @@ PP(pp_sleep) PerlProc_pause(); else { duration = POPi; - PerlProc_sleep((unsigned int)duration); + if (duration < 0) { + /* diag_listed_as: %s() with negative argument */ + Perl_ck_warner_d(aTHX_ packWARN(WARN_MISC), + "sleep() with negative argument"); + SETERRNO(EINVAL, LIB_INVARG); + XPUSHi(0); + RETURN; + } else { + PerlProc_sleep((unsigned int)duration); + } } (void)time(&when); XPUSHi(when - lasttime); |