From 52ce0d8ba9e7c87037658b848822843e1026a6c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Wed, 10 Oct 2018 17:06:19 +0200
Subject: [PATCH] Fix bug with discretionary_policy

Since, in this case, there are less equations than endogenous, the
variable_reordered structure was not filled with enough element, leading to an
invalid memory read when printing M_.state_var.

Ref #637
---
 src/ModelTree.cc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/ModelTree.cc b/src/ModelTree.cc
index 6ae678bd..a5fa1196 100644
--- a/src/ModelTree.cc
+++ b/src/ModelTree.cc
@@ -2052,10 +2052,10 @@ void
 ModelTree::initializeVariablesAndEquations()
 {
   for (size_t j = 0; j < equations.size(); j++)
-    {
-      equation_reordered.push_back(j);
-      variable_reordered.push_back(j);
-    }
+    equation_reordered.push_back(j);
+
+  for (int j = 0; j < symbol_table.endo_nbr(); j++)
+    variable_reordered.push_back(j);
 }
 
 void
-- 
GitLab