toke.c: S_scan_heredoc: prune dead code
authorFather Chrysostomos <sprout@cpan.org>
Wed, 29 Aug 2012 05:37:10 +0000 (22:37 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 31 Aug 2012 01:18:07 +0000 (18:18 -0700)
This incorrect code (using a pointer after finding it to be null)
is the result of the refactoring in 60f40a3895.  It was trying to
account for a string eval with no line break in it.  But that can’t
happen as of 11076590 (if it could it would crash).

So remove it and add an assertion, along with a comment explaining the
assertion.

toke.c

diff --git a/toke.c b/toke.c
index c41a614..665f977 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -9648,6 +9648,12 @@ S_scan_heredoc(pTHX_ register char *s)
        PERL_CONTEXT * const cx = &cxstack[cxstack_ix];
        do {
            shared = shared->ls_prev;
+           /* shared is only null if we have gone beyond the outermost
+              lexing scope.  In a file, we will have broken out of the
+              loop in the previous iteration.  In an eval, the string buf-
+              fer ends with "\n;", so the while condition below will have
+              evaluated to false.  So shared can never be null. */
+           assert(shared);
            /* A LEXSHARED struct with a null ls_prev pointer is the outer-
               most lexing scope.  In a file, shared->ls_linestr at that
               level is just one line, so there is no body to steal. */
@@ -9655,10 +9661,6 @@ S_scan_heredoc(pTHX_ register char *s)
                s = real_olds;
                goto streaming;
            }
-           else if (!shared) {
-               s = SvEND(shared->ls_linestr);
-               break;
-           }
        } while (!(s = (char *)memchr(
                    (void *)shared->ls_bufptr, '\n',
                    SvEND(shared->ls_linestr)-shared->ls_bufptr