Skip to content

Commit

Permalink
fileno might return negative.
Browse files Browse the repository at this point in the history
(Coverity CID 104853)

Also rewrite the fstat call to test for zero (success) explicitly,
instead of the sneaky bang-negation.
  • Loading branch information
jhi committed Jun 27, 2015
1 parent 393bc9b commit 96e1df1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sv.c
Expand Up @@ -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
Expand Down

0 comments on commit 96e1df1

Please sign in to comment.