This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
O_BINARY versus O_TEXT.
authorJarkko Hietaniemi <jhi@iki.fi>
Thu, 29 May 2014 15:18:24 +0000 (11:18 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Thu, 29 May 2014 15:25:50 +0000 (11:25 -0400)
O_BINARY and O_TEXT can be either different (mostly in Windowsy platforms,
and in some hybrids, and then they can be either effective or no-ops);
or equal (in UNIXy platforms, no-ops).  If they are no-ops, and especially
if one or both of them are zeros, one cannot even test for them (bit-and),
without introducing dead/non-sensical code.

[perl #121739]

Fix for Coverity perl5 CID 28948:
Logically dead code (DEADCODE)
dead_error_line: Execution cannot reach this statement mode[ix++] = 'b';

op.c
perl.h
perlio.c

diff --git a/op.c b/op.c
index 2226a94..75aae39 100644 (file)
--- a/op.c
+++ b/op.c
@@ -8621,6 +8621,7 @@ Perl_ck_anoncode(pTHX_ OP *o)
 static void
 S_io_hints(pTHX_ OP *o)
 {
+#ifdef PERLIO_BINARY_AND_TEXT_DIFFERENT_AND_EFFECTIVE
     HV * const table =
        PL_hints & HINT_LOCALIZE_HH ? GvHV(PL_hintgv) : NULL;;
     if (table) {
@@ -8646,6 +8647,9 @@ S_io_hints(pTHX_ OP *o)
                o->op_private |= OPpOPEN_OUT_CRLF;
        }
     }
+#else
+    PERL_UNUSED_ARG(o);
+#endif
 }
 
 OP *
diff --git a/perl.h b/perl.h
index 7bfc445..ab95db7 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -5665,7 +5665,7 @@ int flock(int fd, int op);
 #endif
 
 #if O_TEXT != O_BINARY
-    /* If you have different O_TEXT and O_BINARY and you are a CLRF shop,
+    /* If you have different O_TEXT and O_BINARY and you are a CRLF shop,
      * that is, you are somehow DOSish. */
 #   if defined(__HAIKU__) || defined(__VOS__) || defined(__CYGWIN__)
     /* Haiku has O_TEXT != O_BINARY but O_TEXT and O_BINARY have no effect;
@@ -5679,6 +5679,14 @@ int flock(int fd, int op);
     /* If you really are DOSish. */
 #      define PERLIO_USING_CRLF 1
 #   endif
+#   if O_TEXT != 0 && O_BINARY != 0
+#     if !defined(__HAIKU__)
+        /* If you have O_TEXT different from your O_BINARY and
+         * they are both not zero (being zero would make testing
+         * with bit-and interesting) and they have an effect. */
+#       define PERLIO_BINARY_AND_TEXT_DIFFERENT_AND_EFFECTIVE
+#     endif
+#   endif
 #endif
 
 #ifdef I_LIBUTIL
index c3767f0..4dc3ec3 100644 (file)
--- a/perlio.c
+++ b/perlio.c
@@ -199,8 +199,10 @@ PerlIO_intmode2str(int rawmode, char *mode, int *writing)
            mode[ix++] = '+';
        }
     }
+#ifdef PERLIO_BINARY_AND_TEXT_DIFFERENT_AND_EFFECTIVE
     if (rawmode & O_BINARY)
        mode[ix++] = 'b';
+#endif
     mode[ix] = '\0';
     return ptype;
 }
@@ -2529,6 +2531,7 @@ PerlIOUnix_oflags(const char *mode)
            oflags |= O_WRONLY;
        break;
     }
+#ifdef PERLIO_BINARY_AND_TEXT_DIFFERENT_AND_EFFECTIVE
     if (*mode == 'b') {
        oflags |= O_BINARY;
        oflags &= ~O_TEXT;
@@ -2540,14 +2543,13 @@ PerlIOUnix_oflags(const char *mode)
        mode++;
     }
     else {
-#ifdef PERLIO_USING_CRLF
        /*
         * If neither "t" nor "b" was specified, open the file
         * in O_BINARY mode.
         */
        oflags |= O_BINARY;
-#endif
     }
+#endif
     if (*mode || oflags == -1) {
        SETERRNO(EINVAL, LIB_INVARG);
        oflags = -1;