From c5ee2135734475fb187b41accfd390dc0b6d8a97 Mon Sep 17 00:00:00 2001 From: LAUN Wolfgang Date: Fri, 2 Jan 2004 12:31:46 +0100 Subject: [PATCH] Re: [perl #24774] eval + format - \n = pp_ctl.c assertion Message-ID: eval of of a truncated format should fail p4raw-id: //depot/perl@22055 --- t/op/write.t | 8 ++++---- toke.c | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/t/op/write.t b/t/op/write.t index 85b5f26..2e90b39 100755 --- a/t/op/write.t +++ b/t/op/write.t @@ -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 --- 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; -- 2.7.4