浏览代码

Corrected YAML file parsing
* Fixes #2323.
* YAML file parsing will now properly catch and display warnings when unable to read a file.
Thanks to @CairoLee!

aleos 7 年之前
父节点
当前提交
dcbb2df776
共有 2 个文件被更改,包括 3 次插入1 次删除
  1. 1 1
      3rdparty/yaml-cpp/src/parse.cpp
  2. 2 0
      src/common/yamlwrapper.cpp

+ 1 - 1
3rdparty/yaml-cpp/src/parse.cpp

@@ -31,7 +31,7 @@ Node Load(std::istream& input) {
 
 
 Node LoadFile(const std::string& filename) {
 Node LoadFile(const std::string& filename) {
   std::ifstream fin(filename.c_str());
   std::ifstream fin(filename.c_str());
-  if (!fin) {
+  if (fin.bad()) {
     throw BadFile();
     throw BadFile();
   }
   }
   return Load(fin);
   return Load(fin);

+ 2 - 0
src/common/yamlwrapper.cpp

@@ -47,6 +47,8 @@ yamlwrapper* yaml_load_file(const char* file_name) {
 		node = YAML::LoadFile(file_name);
 		node = YAML::LoadFile(file_name);
 		if (!node.IsDefined())
 		if (!node.IsDefined())
 			return NULL;
 			return NULL;
+		if (node.IsNull())
+			return NULL;
 	} catch (YAML::ParserException &e) {
 	} catch (YAML::ParserException &e) {
 		ShowError("YAML Exception Caught: %s\n", e.what());
 		ShowError("YAML Exception Caught: %s\n", e.what());
 		return NULL;
 		return NULL;