Fixed a crash when using certain invalid color= values
The specific case that brought this to our attention was color=100. In case such values are used, the color reverts back to the default color for that side, as before. The new codepath (team::get_side_color_id_from_config) is essentially the same as the old one but more robust (range checking, for example, the lack of which was causing the crash before).
This commit is contained in:
parent
a76135d107
commit
c95eb01684
2 changed files with 16 additions and 17 deletions
|
@ -45,6 +45,7 @@
|
|||
* Document --log-none in the wesnoth(6) manpage.
|
||||
* Avoid trying to load invalid base64-encoded data URIs.
|
||||
* wesnoth_addon_manager and the addons.wesnoth.org web index can now use data URIs.
|
||||
* Fixed a crash when using certain invalid color= values.
|
||||
|
||||
## Version 1.14.0
|
||||
### Campaigns
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "log.hpp"
|
||||
#include "map/map.hpp"
|
||||
#include "mt_rng.hpp"
|
||||
#include "team.hpp"
|
||||
#include "tod_manager.hpp"
|
||||
#include "wesnothd_connection.hpp"
|
||||
|
||||
|
@ -961,24 +962,21 @@ side_engine::side_engine(const config& cfg, connect_engine& parent_engine, const
|
|||
team_ = team_name_index;
|
||||
}
|
||||
|
||||
if(!cfg["color"].empty()) {
|
||||
if(cfg["color"].to_int()) {
|
||||
color_ = cfg["color"].to_int() - 1;
|
||||
color_id_ = color_options_[color_];
|
||||
// Check the value of the config's color= key.
|
||||
const std::string given_color = team::get_side_color_id_from_config(cfg_);
|
||||
|
||||
if(!given_color.empty()) {
|
||||
// If it's valid, save the color...
|
||||
color_id_ = given_color;
|
||||
|
||||
// ... and find the appropriate index for it.
|
||||
const auto iter = std::find(color_options_.begin(), color_options_.end(), color_id_);
|
||||
|
||||
if(iter != color_options_.end()) {
|
||||
color_ = std::distance(color_options_.begin(), iter);
|
||||
} else {
|
||||
const std::string custom_color = cfg["color"].str();
|
||||
|
||||
const auto iter = std::find(color_options_.begin(), color_options_.end(), custom_color);
|
||||
|
||||
if(iter != color_options_.end()) {
|
||||
color_id_ = *iter;
|
||||
color_ = std::distance(color_options_.begin(), iter);
|
||||
} else {
|
||||
color_options_.push_back(custom_color);
|
||||
|
||||
color_id_ = custom_color;
|
||||
color_ = color_options_.size() - 1;
|
||||
}
|
||||
color_options_.push_back(color_id_);
|
||||
color_ = color_options_.size() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue