fixup use of operator !=(attribute_value, const char*)

since we don't use t_string's == operator anymore in this case, c["a"]
!= "" will evaluate to true in case of "a" beeing not existent. To get
the desired behaviour we need to use the .empty() method.

I also add an assert in map_generation for a possible segfault that i
noticed during fixing this.
This commit is contained in:
gfgtdf 2014-06-27 19:16:35 +02:00
parent 852b698132
commit 484d926c30
4 changed files with 7 additions and 5 deletions

View File

@ -22,6 +22,7 @@
#include "scoped_resource.hpp" #include "scoped_resource.hpp"
#include "serialization/string_utils.hpp" #include "serialization/string_utils.hpp"
#include <cassert>
static lg::log_domain log_config("config"); static lg::log_domain log_config("config");
#define ERR_CF LOG_STREAM(err, log_config) #define ERR_CF LOG_STREAM(err, log_config)
@ -46,6 +47,7 @@ std::string random_generate_map(const std::string& parms, const config &cfg)
//the first token is the name of the generator, tokens after //the first token is the name of the generator, tokens after
//that are arguments to the generator //that are arguments to the generator
std::vector<std::string> parameters = utils::split(parms, ' '); std::vector<std::string> parameters = utils::split(parms, ' ');
assert(!parameters.empty()); //we use parameters.front() in the next line.
util::scoped_ptr<map_generator> generator(create_map_generator(parameters.front(),cfg)); util::scoped_ptr<map_generator> generator(create_map_generator(parameters.front(),cfg));
if(generator == NULL) { if(generator == NULL) {
ERR_CF << "could not find map generator '" << parameters.front() << "'" << std::endl; ERR_CF << "could not find map generator '" << parameters.front() << "'" << std::endl;

View File

@ -958,7 +958,7 @@ void parse_config_internal(const config *help_cfg, const config *section_cfg,
} else if ((*section_cfg)["sort_topics"] == "generated") { } else if ((*section_cfg)["sort_topics"] == "generated") {
sort_topics = false; sort_topics = false;
sort_generated = true; sort_generated = true;
} else if ((*section_cfg)["sort_topics"] != "") { } else if (!(*section_cfg)["sort_topics"].empty()) {
std::stringstream ss; std::stringstream ss;
ss << "Invalid sort option: '" << (*section_cfg)["sort_topics"] << "'"; ss << "Invalid sort option: '" << (*section_cfg)["sort_topics"] << "'";
throw parse_error(ss.str()); throw parse_error(ss.str());

View File

@ -463,7 +463,7 @@ void wait::process_network_data(const config& data, const network::connection so
{ {
ui::process_network_data(data, sock); ui::process_network_data(data, sock);
if(data["message"] != "") { if(!data["message"].empty()) {
gui2::show_transient_message(disp().video() gui2::show_transient_message(disp().video()
, _("Response") , _("Response")
, data["message"]); , data["message"]);

View File

@ -315,7 +315,7 @@ void saved_game::expand_random_scenario()
if(this->starting_pos_type_ == STARTINGPOS_SCENARIO) if(this->starting_pos_type_ == STARTINGPOS_SCENARIO)
{ {
// If the entire scenario should be randomly generated // If the entire scenario should be randomly generated
if(starting_pos_["scenario_generation"] != "") if(!starting_pos_["scenario_generation"].empty())
{ {
LOG_NG << "randomly generating scenario...\n"; LOG_NG << "randomly generating scenario...\n";
const cursor::setter cursor_setter(cursor::WAIT); const cursor::setter cursor_setter(cursor::WAIT);
@ -331,12 +331,12 @@ void saved_game::expand_random_scenario()
update_label(); update_label();
} }
//it looks like we support a map= where map=filename equals more or less map_data={filename} //it looks like we support a map= where map=filename equals more or less map_data={filename}
if(starting_pos_["map_data"].empty() && starting_pos_["map"] != "") { if(starting_pos_["map_data"].empty() && !starting_pos_["map"].empty()) {
starting_pos_["map_data"] = read_map(starting_pos_["map"]); starting_pos_["map_data"] = read_map(starting_pos_["map"]);
} }
// If the map should be randomly generated // If the map should be randomly generated
// We dont want that we accidently to this twice so we check for starting_pos_["map_data"].empty() // We dont want that we accidently to this twice so we check for starting_pos_["map_data"].empty()
if(starting_pos_["map_data"].empty() && starting_pos_["map_generation"] != "") { if(starting_pos_["map_data"].empty() && !starting_pos_["map_generation"].empty()) {
LOG_NG << "randomly generating map...\n"; LOG_NG << "randomly generating map...\n";
const cursor::setter cursor_setter(cursor::WAIT); const cursor::setter cursor_setter(cursor::WAIT);