Просмотр исходного кода

Added error checking to LoadFile to catch NULL pointer errors when the file specified can not be loaded or is empty

David Wimsey 11 лет назад
Родитель
Сommit
19d2cccd45
1 измененных файлов с 11 добавлено и 0 удалено
  1. 11 0
      Source/Core/Lua/Interpreter.cpp

+ 11 - 0
Source/Core/Lua/Interpreter.cpp

@@ -107,7 +107,18 @@ void Interpreter::LoadFile(const String& file)
     //use the file interface to get the contents of the script
     Rocket::Core::FileInterface* file_interface = Rocket::Core::GetFileInterface();
     Rocket::Core::FileHandle handle = file_interface->Open(file);
+    if(handle == 0) {
+        lua_pushfstring(_L, "LoadFile: Unable to open file: %s", file.CString());
+        Report(_L);
+        return;
+    }
+
     size_t size = file_interface->Length(handle);
+    if(size == 0) {
+        lua_pushfstring(_L, "LoadFile: File is 0 bytes in size: %s", file.CString());
+        Report(_L);
+        return;
+    }
     char* file_contents = new char[size];
     file_interface->Read(file_contents,size,handle);
     file_interface->Close(handle);