This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
For HP-UX, do not potentially deref NULL CopFILESV.
authorJarkko Hietaniemi <jhi@iki.fi>
Mon, 16 Jun 2014 16:06:48 +0000 (12:06 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Mon, 16 Jun 2014 23:22:05 +0000 (19:22 -0400)
(HP-UX and other ARG_ZERO_IS_SCRIPT platforms)

toke.c

diff --git a/toke.c b/toke.c
index e1a7694..877bf40 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -4776,25 +4776,32 @@ Perl_yylex(pTHX)
                     * at least, set argv[0] to the basename of the Perl
                     * interpreter. So, having found "#!", we'll set it right.
                     */
-                   SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
-                                                   SVt_PV)); /* $^X */
-                   assert(SvPOK(x) || SvGMAGICAL(x));
-                   if (sv_eq(x, CopFILESV(PL_curcop))) {
-                       sv_setpvn(x, ipath, ipathend - ipath);
-                       SvSETMAGIC(x);
-                   }
-                   else {
-                       STRLEN blen;
-                       STRLEN llen;
-                       const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
-                       const char * const lstart = SvPV_const(x,llen);
-                       if (llen < blen) {
-                           bstart += blen - llen;
-                           if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
-                               sv_setpvn(x, ipath, ipathend - ipath);
-                               SvSETMAGIC(x);
-                           }
+                    SV* copfilesv = CopFILESV(PL_curcop);
+                    if (copfilesv) {
+                        SV * const x =
+                            GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
+                                             SVt_PV)); /* $^X */
+                        assert(SvPOK(x) || SvGMAGICAL(x));
+                        if (sv_eq(x, copfilesv)) {
+                            sv_setpvn(x, ipath, ipathend - ipath);
+                            SvSETMAGIC(x);
+                        }
+                        else {
+                            STRLEN blen;
+                            STRLEN llen;
+                            const char *bstart = SvPV_const(copfilesv, blen);
+                            const char * const lstart = SvPV_const(x, llen);
+                            if (llen < blen) {
+                                bstart += blen - llen;
+                                if (strnEQ(bstart, lstart, llen) &&    bstart[-1] == '/') {
+                                    sv_setpvn(x, ipath, ipathend - ipath);
+                                    SvSETMAGIC(x);
+                                }
+                            }
                        }
+                    }
+                    else {
+                        /* Anything to do if no copfilesv? */
                    }
                    TAINT_NOT;  /* $^X is always tainted, but that's OK */
                }