summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2015-06-22 07:25:27 -0400
committerJarkko Hietaniemi <jhi@iki.fi>2015-06-26 23:09:39 -0400
commit96e1df159163b60ee36220bfa318a5e541a3ab5e (patch)
treee290edcb1fc453f0092bde636452eb6f86942e0b /sv.c
parent393bc9b3483a2e80d10a63fec99c2b2088b66154 (diff)
downloadperl-96e1df159163b60ee36220bfa318a5e541a3ab5e.tar.gz
fileno might return negative.
(Coverity CID 104853) Also rewrite the fstat call to test for zero (success) explicitly, instead of the sneaky bang-negation.
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/sv.c b/sv.c
index 7896e18bcb..b7fb41d77b 100644
--- a/sv.c
+++ b/sv.c
@@ -8306,7 +8306,8 @@ Perl_sv_gets(pTHX_ SV *const sv, PerlIO *const fp, I32 append)
the size we read (e.g. CRLF or a gzip layer).
*/
Stat_t st;
- if (!PerlLIO_fstat(PerlIO_fileno(fp), &st) && S_ISREG(st.st_mode)) {
+ int fd = PerlIO_fileno(fp);
+ if (fd >= 0 && (PerlLIO_fstat(fd, &st) == 0) && S_ISREG(st.st_mode)) {
const Off_t offset = PerlIO_tell(fp);
if (offset != (Off_t) -1 && st.st_size + append > offset) {
#ifdef PERL_NEW_COPY_ON_WRITE