widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #11873
[Merge] lp:~widelands-dev/widelands/bug-1735980-save-map into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1735980-save-map into lp:widelands.
Commit message:
Fixed segfault with saving map in editor
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1735980 in widelands: "use-after-free in editor"
https://bugs.launchpad.net/widelands/+bug/1735980
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1735980-save-map/+merge/334638
If there is no map filesystem, we can't query it -> boom
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1735980-save-map into lp:widelands.
=== modified file 'src/map_io/map_scripting_packet.cc'
--- src/map_io/map_scripting_packet.cc 2017-11-21 16:27:31 +0000
+++ src/map_io/map_scripting_packet.cc 2017-12-03 11:10:30 +0000
@@ -41,16 +41,15 @@
// Write all .lua files that exist in the given 'path' in 'map_fs' to the 'target_fs'.
void write_lua_dir(FileSystem& target_fs, FileSystem* map_fs, const std::string& path) {
- if (map_fs) {
- target_fs.ensure_directory_exists(path);
- for (const std::string& script :
- filter(map_fs->list_directory(path),
- [](const std::string& fn) { return boost::ends_with(fn, ".lua"); })) {
- size_t length;
- void* input_data = map_fs->load(script, length);
- target_fs.write(script, input_data, length);
- free(input_data);
- }
+ assert(map_fs);
+ target_fs.ensure_directory_exists(path);
+ for (const std::string& script :
+ filter(map_fs->list_directory(path),
+ [](const std::string& fn) { return boost::ends_with(fn, ".lua"); })) {
+ size_t length;
+ void* input_data = map_fs->load(script, length);
+ target_fs.write(script, input_data, length);
+ free(input_data);
}
}
} // namespace
@@ -84,11 +83,12 @@
void MapScriptingPacket::write(FileSystem& fs, EditorGameBase& egbase, MapObjectSaver& mos) {
// Write any scenario scripting files in the map's basic scripting dir
FileSystem* map_fs = egbase.map().filesystem();
- write_lua_dir(fs, map_fs, "scripting");
-
- // Write any custom scenario tribe entities
- if (map_fs->file_exists("scripting/tribes/init.lua")) {
- write_lua_dir(fs, map_fs, "scripting/tribes");
+ if (map_fs) {
+ write_lua_dir(fs, map_fs, "scripting");
+ // Write any custom scenario tribe entities
+ if (map_fs->file_exists("scripting/tribes/init.lua")) {
+ write_lua_dir(fs, map_fs, "scripting/tribes");
+ }
}
// Dump the global environment if this is a game and not in the editor
Follow ups