mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/gh-167'
* origin/topic/jsiwek/gh-167: GH-167: improve error message for unclosed function at EOF
This commit is contained in:
commit
7465bceb7e
7 changed files with 57 additions and 12 deletions
4
CHANGES
4
CHANGES
|
@ -1,4 +1,8 @@
|
|||
|
||||
2.6-105 | 2019-01-24 15:22:31 -0800
|
||||
|
||||
* GH-167: improve error message for unclosed function at EOF (Jon Siwek, Corelight)
|
||||
|
||||
2.6-103 | 2019-01-24 17:09:05 -0600
|
||||
|
||||
* Change digest.h functions to use EVP_MD_CTX interface (Johanna Amann)
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
2.6-103
|
||||
2.6-105
|
||||
|
|
31
src/parse.y
31
src/parse.y
|
@ -94,6 +94,9 @@
|
|||
#include <string>
|
||||
|
||||
extern const char* filename; // Absolute path of file currently being parsed.
|
||||
extern const char* last_filename; // Absolute path of last file parsed.
|
||||
extern const char* last_tok_filename;
|
||||
extern const char* last_last_tok_filename;
|
||||
|
||||
YYLTYPE GetCurrentLocation();
|
||||
extern int yyerror(const char[]);
|
||||
|
@ -1723,19 +1726,27 @@ opt_deprecated:
|
|||
|
||||
int yyerror(const char msg[])
|
||||
{
|
||||
char* msgbuf = new char[strlen(msg) + strlen(last_tok) + 128];
|
||||
|
||||
if ( last_tok[0] == '\n' )
|
||||
sprintf(msgbuf, "%s, on previous line", msg);
|
||||
else if ( last_tok[0] == '\0' )
|
||||
sprintf(msgbuf, "%s, at end of file", msg);
|
||||
else
|
||||
sprintf(msgbuf, "%s, at or near \"%s\"", msg, last_tok);
|
||||
|
||||
if ( in_debug )
|
||||
g_curr_debug_error = copy_string(msg);
|
||||
|
||||
reporter->Error("%s", msgbuf);
|
||||
if ( last_tok[0] == '\n' )
|
||||
reporter->Error("%s, on previous line", msg);
|
||||
else if ( last_tok[0] == '\0' )
|
||||
{
|
||||
if ( last_filename )
|
||||
reporter->Error("%s, at end of file %s", msg, last_filename);
|
||||
else
|
||||
reporter->Error("%s, at end of file", msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( last_last_tok_filename && last_tok_filename &&
|
||||
! streq(last_last_tok_filename, last_tok_filename) )
|
||||
reporter->Error("%s, at or near \"%s\" or end of file %s",
|
||||
msg, last_tok, last_last_tok_filename);
|
||||
else
|
||||
reporter->Error("%s, at or near \"%s\"", msg, last_tok);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -43,11 +43,16 @@ int_list if_stack;
|
|||
|
||||
int line_number = 1;
|
||||
const char* filename = 0; // Absolute path of file currently being parsed.
|
||||
const char* last_filename = 0; // Absolute path of last file parsed.
|
||||
static const char* last_id_tok = 0;
|
||||
|
||||
const char* last_tok_filename = 0;
|
||||
const char* last_last_tok_filename = 0;
|
||||
char last_tok[128];
|
||||
|
||||
#define YY_USER_ACTION strncpy(last_tok, yytext, sizeof(last_tok) - 1);
|
||||
#define YY_USER_ACTION strncpy(last_tok, yytext, sizeof(last_tok) - 1); \
|
||||
last_last_tok_filename = last_tok_filename; \
|
||||
last_tok_filename = ::filename;
|
||||
#define YY_USER_INIT last_tok[0] = '\0';
|
||||
|
||||
// We define our own YY_INPUT because we want to trap the case where
|
||||
|
@ -899,6 +904,8 @@ void add_to_name_list(char* s, char delim, name_list& nl)
|
|||
|
||||
int yywrap()
|
||||
{
|
||||
last_filename = ::filename;
|
||||
|
||||
if ( reporter->Errors() > 0 )
|
||||
return 1;
|
||||
|
||||
|
|
1
testing/btest/Baseline/language.eof-parse-errors/output1
Normal file
1
testing/btest/Baseline/language.eof-parse-errors/output1
Normal file
|
@ -0,0 +1 @@
|
|||
error: syntax error, at end of file ./a.bro
|
1
testing/btest/Baseline/language.eof-parse-errors/output2
Normal file
1
testing/btest/Baseline/language.eof-parse-errors/output2
Normal file
|
@ -0,0 +1 @@
|
|||
error in ./b.bro, line 1: syntax error, at or near "module" or end of file ./a.bro
|
21
testing/btest/language/eof-parse-errors.bro
Normal file
21
testing/btest/language/eof-parse-errors.bro
Normal file
|
@ -0,0 +1,21 @@
|
|||
# @TEST-EXEC-FAIL: bro -b a.bro >output1 2>&1
|
||||
# @TEST-EXEC-FAIL: bro -b a.bro b.bro >output2 2>&1
|
||||
# @TEST-EXEC: btest-diff output1
|
||||
# @TEST-EXEC: btest-diff output2
|
||||
|
||||
@TEST-START-FILE a.bro
|
||||
module A;
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
print "a";
|
||||
@TEST-END-FILE
|
||||
|
||||
@TEST-START-FILE b.bro
|
||||
module B;
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
print "b";
|
||||
}
|
||||
@TEST-END-FILE
|
Loading…
Add table
Add a link
Reference in a new issue