From 5b0b38cbdcccedb8b700845fca83535d3bf4930d Mon Sep 17 00:00:00 2001
From: Karsten Rink <karsten.rink@ufz.de>
Date: Thu, 30 Oct 2014 11:41:28 +0100
Subject: [PATCH] check input stream

---
 FileIO/GMSHInterface.cpp | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/FileIO/GMSHInterface.cpp b/FileIO/GMSHInterface.cpp
index 54e98f4c56c..ffa30ccb303 100644
--- a/FileIO/GMSHInterface.cpp
+++ b/FileIO/GMSHInterface.cpp
@@ -103,10 +103,13 @@ MeshLib::Mesh* GMSHInterface::readGMSHMesh(std::string const& fname)
 {
 	std::string line;
 	std::ifstream in(fname.c_str(), std::ios::in);
-	getline(in, line); // Node keyword
-	std::vector<MeshLib::Node*> nodes;
-	std::vector<MeshLib::Element*> elements;
+	if (!in.is_open())
+	{
+		WARN ("GMSHInterface::readGMSHMesh() - Could not open file %s.", fname.c_str());
+		return nullptr;
+	}
 
+	getline(in, line); // $MeshFormat keyword
 	if (line.find("$MeshFormat") == std::string::npos)
 	{
 		in.close();
@@ -126,6 +129,8 @@ MeshLib::Mesh* GMSHInterface::readGMSHMesh(std::string const& fname)
 	}
 	getline(in, line); //$EndMeshFormat
 
+	std::vector<MeshLib::Node*> nodes;
+	std::vector<MeshLib::Element*> elements;
 	std::map<unsigned, unsigned> id_map;
 	while (line.find("$EndElements") == std::string::npos)
 	{
-- 
GitLab