Re: [perl #24774] eval + format - \n = pp_ctl.c assertion
authorLAUN Wolfgang <wolfgang.laun@alcatel.at>
Fri, 2 Jan 2004 11:31:46 +0000 (12:31 +0100)
committerDave Mitchell <davem@fdisolutions.com>
Sun, 4 Jan 2004 19:34:36 +0000 (19:34 +0000)
Message-ID: <DF27CDCBD2581D4B88431901094E4B4D02B0C4B3@attmsx1>

eval of of a truncated format should fail

p4raw-id: //depot/perl@22055

t/op/write.t
toke.c

index 85b5f26..2e90b39 100755 (executable)
@@ -302,12 +302,12 @@ $v
 
 {
     # Bug #24774 format without trailing \n failed assertion
+    # but this must not compile because we'd get a ';' into the format
+
     my @v = ('k');
     eval "format OUT14 = \n@\n\@v";
-    open(OUT14, '>Op_write.tmp') || die "Can't create Op_write.tmp";
-    write(OUT14);
-    close OUT14 or die "Could not close: $!";
-    print "ok 14\n";
+    print $@ ? "ok 14\n" : "not ok 14\n";
+
 }
 
 #######################################
diff --git a/toke.c b/toke.c
index 3b010ec..54831e7 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -2427,8 +2427,12 @@ Perl_yylex(pTHX)
        if (!PL_rsfp) {
            PL_last_uni = 0;
            PL_last_lop = 0;
-           if (PL_lex_brackets)
-               yyerror("Missing right curly or square bracket");
+           if (PL_lex_brackets) {
+               if (PL_lex_formbrack)
+                   yyerror("Format not terminated");
+                else
+                   yyerror("Missing right curly or square bracket");
+           }
             DEBUG_T( { PerlIO_printf(Perl_debug_log,
                         "### Tokener got EOF\n");
             } );
@@ -7603,6 +7607,7 @@ S_scan_formline(pTHX_ register char *s)
     register char *t;
     SV *stuff = newSVpvn("",0);
     bool needargs = FALSE;
+    bool eofmt = FALSE;
 
     while (!needargs) {
        if (*s == '.' || *s == /*{*/'}') {
@@ -7612,8 +7617,10 @@ S_scan_formline(pTHX_ register char *s)
 #else
            for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
 #endif
-           if (*t == '\n' || t == PL_bufend)
+           if (*t == '\n' || t == PL_bufend) {
+               eofmt = TRUE;
                break;
+            }
        }
        if (PL_in_eval && !PL_rsfp) {
            eol = strchr(s,'\n');
@@ -7653,7 +7660,6 @@ S_scan_formline(pTHX_ register char *s)
            PL_last_lop = PL_last_uni = Nullch;
            if (!s) {
                s = PL_bufptr;
-               yyerror("Format not terminated");
                break;
            }
        }
@@ -7682,7 +7688,8 @@ S_scan_formline(pTHX_ register char *s)
     }
     else {
        SvREFCNT_dec(stuff);
-       PL_lex_formbrack = 0;
+       if (eofmt)
+           PL_lex_formbrack = 0;
        PL_bufptr = s;
     }
     return s;