From 12b61e4817553cbebaa08db35cf1c1b221fbaa24 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Mon, 26 Apr 2021 14:10:04 +0200
Subject: [PATCH] Bugfix in DataTree::writeToFileIfModified()

If the old file and the new contents shared a common prefix, then the output in
the generated file would be truncated at the start.

Ref. DynareJulia/Dynare.jl#1
---
 src/DataTree.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/DataTree.cc b/src/DataTree.cc
index 69e7d938..e1f3e104 100644
--- a/src/DataTree.cc
+++ b/src/DataTree.cc
@@ -978,6 +978,8 @@ DataTree::writeToFileIfModified(stringstream &new_contents, const string &filena
     return;
   old_file.close();
 
+  new_contents.seekg(0);
+
   ofstream new_file{filename, ios::out | ios::binary};
   if (!new_file.is_open())
     {
-- 
GitLab