Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No warnings when reading from a file only opened for appending. #9366

Open
p5pRT opened this issue Jun 7, 2008 · 4 comments
Open

No warnings when reading from a file only opened for appending. #9366

p5pRT opened this issue Jun 7, 2008 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 7, 2008

Migrated from rt.perl.org#55420 (status was 'open')

Searchable as RT55420$

@p5pRT
Copy link
Author

p5pRT commented Jun 7, 2008

From @pjf

Created by @pjf

G'day p5p and readers of perlbugs,

Under all versions of Perl I have on my laptop (5.8.4, 5.8.8, 5.10.0, and
5.11.0) the following produces a warning​:

  open(FOO, '>', 'foo.txt');
  <FOO>;

However writing a file for appending doesn't​:

  open(FOO, '>>', 'foo.txt');
  <FOO>;

I thought this would be easy enough to fix​:

Inline Patch
diff --git a/pp_hot.c b/pp_hot.c
index 64b5fc5..bc0d5fe 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1586,7 +1586,8 @@ Perl_do_readline(pTHX)
         }
         else if (type == OP_GLOB)
             SP--;
-       else if (ckWARN(WARN_IO) && IoTYPE(io) == IoTYPE_WRONLY) {
+       else if (ckWARN(WARN_IO) && ( IoTYPE(io) == IoTYPE_WRONLY ||
+                                     IoTYPE(io) == IoTYPE_APPEND)) {
             report_evil_fh(PL_last_in_gv, io, OP_phoney_OUTPUT_ONLY);
         }
      }

However it looks like IoTYPE_APPEND also applies to files opened with mode '\+>>'\, and we certainly don't want to be warning there\.

Am I missing an IoTYPE that signifies a file is open for appending
only, or is the reason this bug is still around because we can't
easily spot the difference between the two?

Many thanks,

  Paul

--
Paul Fenwick <pjf@​perltraining.com.au> | http​://perltraining.com.au/
Director of Training | Ph​: +61 3 9354 6001
Perl Training Australia | Fax​: +61 3 9354 2681

Perl Info

Flags:
     category=core
     severity=low

Site configuration information for perl v5.8.8:

Configured by rurban at Sun Jul  8 19:08:44 GMT 2007.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
   Platform:
     osname=cygwin, osvers=1.5.24(0.15642), archname=cygwin-thread-multi-64int
     uname='cygwin_nt-5.1 reini 1.5.24(0.15642) 2007-01-31 10:57 i686 cygwin '
     config_args='-de -Dmksymlinks -Duse64bitint -Dusethreads -Uusemymalloc
-Doptimize=-O3 -Dman3ext=3pm -Dusesitecustomize -Dusedevel'
     hint=recommended, useposix=true, d_sigaction=define
     usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
     useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
     use64bitint=define use64bitall=undef uselongdouble=undef
     usemymalloc=n, bincompat5005=undef
   Compiler:
     cc='gcc', ccflags ='-DPERL_USE_SAFE_PUTENV -fno-strict-aliasing -pipe
-Wdeclaration-after-statement',
     optimize='-O3',
     cppflags='-DPERL_USE_SAFE_PUTENV -fno-strict-aliasing -pipe
-Wdeclaration-after-statement'
     ccversion='', gccversion='3.4.4 (cygming special, gdc 0.12, using dmd
0.125)', gccosandvers=''
     intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
     ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
     alignbytes=8, prototype=define
   Linker and Libraries:
     ld='ld2', ldflags =' -s -L/usr/local/lib'
     libpth=/usr/local/lib /usr/lib /lib
     libs=-lgdbm -ldb -ldl -lcrypt -lgdbm_compat
     perllibs=-ldl -lcrypt -lgdbm_compat
     libc=/usr/lib/libc.a, so=dll, useshrplib=true, libperl=libperl.a
     gnulibc_version=''
   Dynamic Linking:
     dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' -s'
     cccdlflags=' ', lddlflags=' -s -L/usr/local/lib'

Locally applied patches:
     CYG01 - hints.cygwin.sh ldflags -s
     CYG02 - lib-ExtUtils-Embed insensitive against leading \\s
     CYG03 - lib-Test-Harness-Straps $ENV{PERL5LIB} = ''
     CYG04 - major.version.cygwin.sh cygperl-5_8.dll and not cygperl-5_8_x.dll
     CYG05 - add Win32CORE to core
     CYG07 - File-Spec-Cygwin-TMPDIR.patch
     Bug#38628 - allow legacy Cwd->cwd()
     Bug#40103 - File-Spec-case_tolerant.patch from 5.9.5


@INC for perl v5.8.8:
     /usr/lib/perl5/5.8/cygwin
     /usr/lib/perl5/5.8
     /usr/lib/perl5/site_perl/5.8/cygwin
     /usr/lib/perl5/site_perl/5.8
     /usr/lib/perl5/site_perl/5.8
     /usr/lib/perl5/vendor_perl/5.8/cygwin
     /usr/lib/perl5/vendor_perl/5.8
     /usr/lib/perl5/vendor_perl/5.8
     .


Environment for perl v5.8.8:
     HOME=/home/pjf
     LANG (unset)
     LANGUAGE (unset)
     LD_LIBRARY_PATH (unset)
     LOGDIR (unset)

PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/cygdrive/c/PROGRA~1/PerlEdit:/cygdrive/c/Perl/site/bin:/cygdrive/c/Perl/bin:/cygdrive/c/Perl/bin/:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS:/cygdrive/c/WINDOWS/System32/Wbem:/cygdrive/c/Program
Files/VDMSound/:/cygdrive/c/Program Files/Common
Files/GTK/2.0/bin:/cygdrive/c/MinGW/bin:/cygdrive/c/Program
Files/gs/gs8.54/bin:/cygdrive/c/Program
Files/QuickTime/QTSystem/:/usr/local/bin/netpbm
     PERL_BADLANG (unset)
     SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Jun 8, 2008

From @rgs

2008/6/7 via RT Paul Fenwick <perlbug-followup@​perl.org>​:

Under all versions of Perl I have on my laptop (5.8.4, 5.8.8, 5.10.0, and
5.11.0) the following produces a warning​:

   open\(FOO\, '>'\, 'foo\.txt'\);
   \<FOO>;

However writing a file for appending doesn't​:

   open\(FOO\, '>>'\, 'foo\.txt'\);
   \<FOO>;

I thought this would be easy enough to fix​:

diff --git a/pp_hot.c b/pp_hot.c
index 64b5fc5..bc0d5fe 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@​@​ -1586,7 +1586,8 @​@​ Perl_do_readline(pTHX)
}
else if (type == OP_GLOB)
SP--;
- else if (ckWARN(WARN_IO) && IoTYPE(io) == IoTYPE_WRONLY) {
+ else if (ckWARN(WARN_IO) && ( IoTYPE(io) == IoTYPE_WRONLY ||
+ IoTYPE(io) == IoTYPE_APPEND)) {
report_evil_fh(PL_last_in_gv, io, OP_phoney_OUTPUT_ONLY);
}
}

However it looks like IoTYPE_APPEND also applies to files opened with mode
'+>>', and we certainly don't want to be warning there.

Am I missing an IoTYPE that signifies a file is open for appending
only, or is the reason this bug is still around because we can't
easily spot the difference between the two?

I think we could add a new IoTYPE.

@p5pRT
Copy link
Author

p5pRT commented Jun 8, 2008

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jan 19, 2018

From zefram@fysh.org

Appending is not the only case where there is insufficient information
in IoTYPE. When a file handle is opened on a command pipe, it gets IoTYPE
'|' regardless of the direction of the pipe, so there's no warning for
reading from a write-only pipe​:

$ perl -lwe 'open(FOO, "|true") or die $!; $a = <FOO>; print "OK"'
OK

We should probably be looking a layer down, asking perlio about the
file handle. Since perlio is now mandatory, it can probably replace
most uses of IoTYPE.

-zefram

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants