From 856c0b53a1823419d651908b1bb8b71066f83b6c Mon Sep 17 00:00:00 2001
From: sebastien <sebastien@ac1d8469-bf42-47a9-8791-bf33cf982152>
Date: Tue, 4 Nov 2008 09:14:58 +0000
Subject: [PATCH] trunk: fixed preprocessor crash when there is an unexpected
 end of file

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@2234 ac1d8469-bf42-47a9-8791-bf33cf982152
---
 DynareFlex.ll    | 6 +-----
 ParsingDriver.cc | 6 ++++++
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/DynareFlex.ll b/DynareFlex.ll
index e64d6fc6..961326a8 100644
--- a/DynareFlex.ll
+++ b/DynareFlex.ll
@@ -407,11 +407,7 @@ int sigma_e = 0;
  /* Add the native statement */
 <NATIVE>.* { driver.add_native(yytext); BEGIN INITIAL; }
 
-<*><<EOF>> {
-             if (yylloc->begin.filename)
-               delete yylloc->begin.filename;
-             yyterminate();
-           }
+<*><<EOF>> { yyterminate(); }
 
 <*>.      { driver.error(*yylloc, "character unrecognized by lexer"); }
 %%
diff --git a/ParsingDriver.cc b/ParsingDriver.cc
index c0f2dc53..1516a026 100644
--- a/ParsingDriver.cc
+++ b/ParsingDriver.cc
@@ -71,6 +71,12 @@ ParsingDriver::parse(istream &in, bool debug)
 
   delete lexer;
 
+  /* Deleting filename in DynareFlex::yyterminate() is prematurate,
+     because if there is an unexpected end of file, the call to
+     ParsingDriver::error() needs filename */
+  if (location.begin.filename)
+    delete location.begin.filename;
+
   return mod_file;
 }
 
-- 
GitLab