Author: fendrin
Date: Wed Mar  9 03:08:39 2011
New Revision: 48826

URL: http://svn.gna.org/viewcvs/wesnoth?rev=48826&view=rev
Log:
Fixed segmentation fault caused by wrong usage of the vconfig class in the 
teleport system.
Spotted by AI and Espreon.
I also had help from crab with getting behind what caused it.

Modified:
    trunk/src/pathfind/teleport.cpp
    trunk/src/pathfind/teleport.hpp

Modified: trunk/src/pathfind/teleport.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/pathfind/teleport.cpp?rev=48826&r1=48825&r2=48826&view=diff
==============================================================================
--- trunk/src/pathfind/teleport.cpp (original)
+++ trunk/src/pathfind/teleport.cpp Wed Mar  9 03:08:39 2011
@@ -29,20 +29,21 @@
 }
 
 // This constructor is *only* meant for loading from saves
-pathfind::teleport_group::teleport_group(const config& cfg) : cfg_(cfg, true), 
reversed_(utils::string_bool(cfg["reversed"], false)), id_(cfg["id"])
+pathfind::teleport_group::teleport_group(const config& cfg) : cfg_(cfg), 
reversed_(utils::string_bool(cfg["reversed"], false)), id_(cfg["id"])
 {
        assert(cfg.has_attribute("id"));
        assert(cfg.has_attribute("reversed"));
-       assert(!cfg_.get_children("source").empty());
-       assert(!cfg_.get_children("target").empty());
-       assert(!cfg_.get_children("filter").empty());
-}
-
-pathfind::teleport_group::teleport_group(const vconfig& cfg, bool reversed) : 
cfg_(cfg), reversed_(reversed), id_()
-{
-       assert(!cfg_.get_children("source").empty());
-       assert(!cfg_.get_children("target").empty());
-       assert(!cfg_.get_children("filter").empty());
+
+       assert(cfg_.child_count("source") == 1);
+       assert(cfg_.child_count("target") == 1);
+       assert(cfg_.child_count("filter") == 1);
+}
+
+pathfind::teleport_group::teleport_group(const vconfig& cfg, bool reversed) : 
cfg_(cfg.get_config()), reversed_(reversed), id_()
+{
+       assert(cfg_.child_count("source") == 1);
+       assert(cfg_.child_count("target") == 1);
+       assert(cfg_.child_count("filter") == 1);
        if (cfg["id"].empty()) {
                id_ = resources::tunnels->next_unique_id();
        } else {
@@ -65,14 +66,17 @@
        } else {
                units = resources::units;
        }
-       if (u.matches_filter(cfg_.child("filter"), loc)) {
+       vconfig filter(cfg_.child_or_empty("filter"), true);
+       vconfig source(cfg_.child_or_empty("source"), true);
+       vconfig target(cfg_.child_or_empty("target"), true);
+       if (u.matches_filter(filter, loc)) {
 
                scoped_xy_unit teleport_unit("teleport_unit", loc.x, loc.y, 
*resources::units);
 
-               terrain_filter source_filter(cfg_.child("source"), *units);
+               terrain_filter source_filter(source, *units);
                source_filter.get_locations(reversed_ ? loc_pair.second : 
loc_pair.first);
 
-               terrain_filter target_filter(cfg_.child("target"), *units);
+               terrain_filter target_filter(target, *units);
                target_filter.get_locations(reversed_ ? loc_pair.first : 
loc_pair.second);
        }
 }
@@ -86,7 +90,7 @@
 }
 
 config pathfind::teleport_group::to_config() const {
-       config retval = cfg_.get_config();
+       config retval = cfg_;
        retval["reversed"] = reversed_ ? "yes" : "no";
        retval["id"] = id_;
        return retval;

Modified: trunk/src/pathfind/teleport.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/pathfind/teleport.hpp?rev=48826&r1=48825&r2=48826&view=diff
==============================================================================
--- trunk/src/pathfind/teleport.hpp (original)
+++ trunk/src/pathfind/teleport.hpp Wed Mar  9 03:08:39 2011
@@ -66,7 +66,7 @@
 
 private:
 
-       vconfig cfg_;
+       config cfg_;
        bool reversed_;
        std::string id_;
 };
@@ -100,7 +100,6 @@
        std::map<std::string, std::set<map_location> > targets_;
 };
 
-//TODO clean up the interface
 const teleport_map get_teleport_locations(const unit &u, const team 
&viewing_team,
                bool see_all = false, bool ignore_units = false);
 


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to