Change do_compare to take reference instead of ptr
Resolves potential nullptr dereference.
This commit is contained in:
parent
bff19779a4
commit
f0de25a19c
6 changed files with 35 additions and 35 deletions
|
@ -69,9 +69,9 @@ void move_map_callable::get_inputs(formula_input_vector& inputs) const
|
||||||
add_input(inputs, "moves");
|
add_input(inputs, "moves");
|
||||||
}
|
}
|
||||||
|
|
||||||
int move_callable::do_compare(const formula_callable* callable) const
|
int move_callable::do_compare(const formula_callable& callable) const
|
||||||
{
|
{
|
||||||
const move_callable* mv_callable = dynamic_cast<const move_callable*>(callable);
|
const move_callable* mv_callable = dynamic_cast<const move_callable*>(&callable);
|
||||||
if(mv_callable == nullptr) {
|
if(mv_callable == nullptr) {
|
||||||
return formula_callable::do_compare(callable);
|
return formula_callable::do_compare(callable);
|
||||||
}
|
}
|
||||||
|
@ -98,9 +98,9 @@ variant move_callable::execute_self(variant ctxt) {
|
||||||
return variant(move_result->is_gamestate_changed());
|
return variant(move_result->is_gamestate_changed());
|
||||||
}
|
}
|
||||||
|
|
||||||
int move_partial_callable::do_compare(const formula_callable* callable) const
|
int move_partial_callable::do_compare(const formula_callable& callable) const
|
||||||
{
|
{
|
||||||
const move_partial_callable* mv_callable = dynamic_cast<const move_partial_callable*>(callable);
|
const move_partial_callable* mv_callable = dynamic_cast<const move_partial_callable*>(&callable);
|
||||||
if(mv_callable == nullptr) {
|
if(mv_callable == nullptr) {
|
||||||
return formula_callable::do_compare(callable);
|
return formula_callable::do_compare(callable);
|
||||||
}
|
}
|
||||||
|
@ -184,9 +184,9 @@ void attack_callable::get_inputs(formula_input_vector& inputs) const {
|
||||||
add_input(inputs, "move_from");
|
add_input(inputs, "move_from");
|
||||||
}
|
}
|
||||||
|
|
||||||
int attack_callable::do_compare(const wfl::formula_callable* callable)
|
int attack_callable::do_compare(const wfl::formula_callable& callable)
|
||||||
const {
|
const {
|
||||||
const attack_callable* a_callable = dynamic_cast<const attack_callable*>(callable);
|
const attack_callable* a_callable = dynamic_cast<const attack_callable*>(&callable);
|
||||||
if(a_callable == nullptr) {
|
if(a_callable == nullptr) {
|
||||||
return formula_callable::do_compare(callable);
|
return formula_callable::do_compare(callable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ public:
|
||||||
/** Compare two attacks in deterministic way or compare pointers
|
/** Compare two attacks in deterministic way or compare pointers
|
||||||
* (nondeterministic in consequent game runs) if method argument is not
|
* (nondeterministic in consequent game runs) if method argument is not
|
||||||
* attack_callable */
|
* attack_callable */
|
||||||
int do_compare(const formula_callable* callable) const override;
|
int do_compare(const formula_callable& callable) const override;
|
||||||
variant execute_self(variant ctxt) override;
|
variant execute_self(variant ctxt) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ class move_callable : public action_callable {
|
||||||
add_input(inputs, "dst");
|
add_input(inputs, "dst");
|
||||||
}
|
}
|
||||||
|
|
||||||
int do_compare(const formula_callable* callable) const override;
|
int do_compare(const formula_callable& callable) const override;
|
||||||
public:
|
public:
|
||||||
move_callable(const map_location& src, const map_location& dst) :
|
move_callable(const map_location& src, const map_location& dst) :
|
||||||
src_(src), dst_(dst)
|
src_(src), dst_(dst)
|
||||||
|
@ -112,7 +112,7 @@ class move_partial_callable : public action_callable {
|
||||||
add_input(inputs, "dst");
|
add_input(inputs, "dst");
|
||||||
}
|
}
|
||||||
|
|
||||||
int do_compare(const formula_callable* callable) const override;
|
int do_compare(const formula_callable& callable) const override;
|
||||||
public:
|
public:
|
||||||
move_partial_callable(const map_location& src, const map_location& dst) :
|
move_partial_callable(const map_location& src, const map_location& dst) :
|
||||||
src_(src), dst_(dst)
|
src_(src), dst_(dst)
|
||||||
|
|
|
@ -71,12 +71,12 @@ public:
|
||||||
|
|
||||||
bool equals(const formula_callable& other) const
|
bool equals(const formula_callable& other) const
|
||||||
{
|
{
|
||||||
return do_compare(&other) == 0;
|
return do_compare(other) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool less(const formula_callable& other) const
|
bool less(const formula_callable& other) const
|
||||||
{
|
{
|
||||||
return do_compare(&other) < 0;
|
return do_compare(other) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has_key(const std::string& key) const
|
bool has_key(const std::string& key) const
|
||||||
|
@ -143,17 +143,17 @@ protected:
|
||||||
PLAIN_LOG << "ERROR: cannot set key '" << key << "' on object";
|
PLAIN_LOG << "ERROR: cannot set key '" << key << "' on object";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int do_compare(const formula_callable* callable) const
|
virtual int do_compare(const formula_callable& callable) const
|
||||||
{
|
{
|
||||||
if(type_ < callable->type_) {
|
if(type_ < callable.type_) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(type_ > callable->type_) {
|
if(type_ > callable.type_) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this < callable ? -1 : (this == callable ? 0 : 1);
|
return this < &callable ? -1 : (this == &callable ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: this function should NOT overwrite str, but append text to it!
|
// Note: this function should NOT overwrite str, but append text to it!
|
||||||
|
|
|
@ -58,9 +58,9 @@ void location_callable::get_inputs(formula_input_vector& inputs) const
|
||||||
add_input(inputs, "y");
|
add_input(inputs, "y");
|
||||||
}
|
}
|
||||||
|
|
||||||
int location_callable::do_compare(const formula_callable* callable) const
|
int location_callable::do_compare(const formula_callable& callable) const
|
||||||
{
|
{
|
||||||
const location_callable* loc_callable = dynamic_cast<const location_callable*>(callable);
|
const location_callable* loc_callable = dynamic_cast<const location_callable*>(&callable);
|
||||||
if(loc_callable == nullptr) {
|
if(loc_callable == nullptr) {
|
||||||
return formula_callable::do_compare(callable);
|
return formula_callable::do_compare(callable);
|
||||||
}
|
}
|
||||||
|
@ -150,9 +150,9 @@ void attack_type_callable::get_inputs(formula_input_vector& inputs) const
|
||||||
add_input(inputs, "specials");
|
add_input(inputs, "specials");
|
||||||
}
|
}
|
||||||
|
|
||||||
int attack_type_callable::do_compare(const formula_callable* callable) const
|
int attack_type_callable::do_compare(const formula_callable& callable) const
|
||||||
{
|
{
|
||||||
const attack_type_callable* att_callable = dynamic_cast<const attack_type_callable*>(callable);
|
const attack_type_callable* att_callable = dynamic_cast<const attack_type_callable*>(&callable);
|
||||||
if(att_callable == nullptr) {
|
if(att_callable == nullptr) {
|
||||||
return formula_callable::do_compare(callable);
|
return formula_callable::do_compare(callable);
|
||||||
}
|
}
|
||||||
|
@ -423,9 +423,9 @@ void unit_callable::get_inputs(formula_input_vector& inputs) const
|
||||||
add_input(inputs, "wml_vars");
|
add_input(inputs, "wml_vars");
|
||||||
}
|
}
|
||||||
|
|
||||||
int unit_callable::do_compare(const formula_callable* callable) const
|
int unit_callable::do_compare(const formula_callable& callable) const
|
||||||
{
|
{
|
||||||
const unit_callable* u_callable = dynamic_cast<const unit_callable*>(callable);
|
const unit_callable* u_callable = dynamic_cast<const unit_callable*>(&callable);
|
||||||
if(u_callable == nullptr) {
|
if(u_callable == nullptr) {
|
||||||
return formula_callable::do_compare(callable);
|
return formula_callable::do_compare(callable);
|
||||||
}
|
}
|
||||||
|
@ -509,9 +509,9 @@ void unit_type_callable::get_inputs(formula_input_vector& inputs) const
|
||||||
add_input(inputs, "usage");
|
add_input(inputs, "usage");
|
||||||
}
|
}
|
||||||
|
|
||||||
int unit_type_callable::do_compare(const formula_callable* callable) const
|
int unit_type_callable::do_compare(const formula_callable& callable) const
|
||||||
{
|
{
|
||||||
const unit_type_callable* u_callable = dynamic_cast<const unit_type_callable*>(callable);
|
const unit_type_callable* u_callable = dynamic_cast<const unit_type_callable*>(&callable);
|
||||||
if(u_callable == nullptr) {
|
if(u_callable == nullptr) {
|
||||||
return formula_callable::do_compare(callable);
|
return formula_callable::do_compare(callable);
|
||||||
}
|
}
|
||||||
|
@ -594,9 +594,9 @@ void config_callable::get_inputs(formula_input_vector& inputs) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int config_callable::do_compare(const formula_callable* callable) const
|
int config_callable::do_compare(const formula_callable& callable) const
|
||||||
{
|
{
|
||||||
const config_callable* cfg_callable = dynamic_cast<const config_callable*>(callable);
|
const config_callable* cfg_callable = dynamic_cast<const config_callable*>(&callable);
|
||||||
if(cfg_callable == nullptr) {
|
if(cfg_callable == nullptr) {
|
||||||
return formula_callable::do_compare(callable);
|
return formula_callable::do_compare(callable);
|
||||||
}
|
}
|
||||||
|
@ -666,9 +666,9 @@ void terrain_callable::get_inputs(formula_input_vector& inputs) const
|
||||||
add_input(inputs, "owner_side");
|
add_input(inputs, "owner_side");
|
||||||
}
|
}
|
||||||
|
|
||||||
int terrain_callable::do_compare(const formula_callable* callable) const
|
int terrain_callable::do_compare(const formula_callable& callable) const
|
||||||
{
|
{
|
||||||
const terrain_callable* terr_callable = dynamic_cast<const terrain_callable*>(callable);
|
const terrain_callable* terr_callable = dynamic_cast<const terrain_callable*>(&callable);
|
||||||
if(terr_callable == nullptr) {
|
if(terr_callable == nullptr) {
|
||||||
return formula_callable::do_compare(callable);
|
return formula_callable::do_compare(callable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ public:
|
||||||
variant get_value(const std::string& key) const override;
|
variant get_value(const std::string& key) const override;
|
||||||
void get_inputs(formula_input_vector& inputs) const override;
|
void get_inputs(formula_input_vector& inputs) const override;
|
||||||
|
|
||||||
int do_compare(const formula_callable* callable) const override;
|
int do_compare(const formula_callable& callable) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const map_location loc_;
|
const map_location loc_;
|
||||||
|
@ -104,7 +104,7 @@ private:
|
||||||
variant get_value(const std::string& key) const override;
|
variant get_value(const std::string& key) const override;
|
||||||
|
|
||||||
void get_inputs(formula_input_vector& inputs) const override;
|
void get_inputs(formula_input_vector& inputs) const override;
|
||||||
int do_compare(const formula_callable* callable) const override;
|
int do_compare(const formula_callable& callable) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class attack_type_callable : public formula_callable
|
class attack_type_callable : public formula_callable
|
||||||
|
@ -115,7 +115,7 @@ public:
|
||||||
variant get_value(const std::string& key) const override;
|
variant get_value(const std::string& key) const override;
|
||||||
void get_inputs(formula_input_vector& inputs) const override;
|
void get_inputs(formula_input_vector& inputs) const override;
|
||||||
|
|
||||||
int do_compare(const formula_callable* callable) const override;
|
int do_compare(const formula_callable& callable) const override;
|
||||||
|
|
||||||
const attack_type& get_attack_type() const { return *att_; }
|
const attack_type& get_attack_type() const { return *att_; }
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ public:
|
||||||
variant get_value(const std::string& key) const override;
|
variant get_value(const std::string& key) const override;
|
||||||
void get_inputs(formula_input_vector& inputs) const override;
|
void get_inputs(formula_input_vector& inputs) const override;
|
||||||
|
|
||||||
int do_compare(const formula_callable* callable) const override;
|
int do_compare(const formula_callable& callable) const override;
|
||||||
|
|
||||||
const unit& get_unit() const { return u_; }
|
const unit& get_unit() const { return u_; }
|
||||||
const map_location& get_location() const { return loc_; }
|
const map_location& get_location() const { return loc_; }
|
||||||
|
@ -157,7 +157,7 @@ public:
|
||||||
variant get_value(const std::string& key) const override;
|
variant get_value(const std::string& key) const override;
|
||||||
void get_inputs(formula_input_vector& inputs) const override;
|
void get_inputs(formula_input_vector& inputs) const override;
|
||||||
|
|
||||||
int do_compare(const formula_callable* callable) const override;
|
int do_compare(const formula_callable& callable) const override;
|
||||||
|
|
||||||
const unit_type& get_unit_type() const { return u_; }
|
const unit_type& get_unit_type() const { return u_; }
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ public:
|
||||||
|
|
||||||
variant get_value(const std::string& key) const override;
|
variant get_value(const std::string& key) const override;
|
||||||
void get_inputs(formula_input_vector& inputs) const override;
|
void get_inputs(formula_input_vector& inputs) const override;
|
||||||
int do_compare(const formula_callable* callable) const override;
|
int do_compare(const formula_callable& callable) const override;
|
||||||
|
|
||||||
const config& get_config() const { return cfg_; }
|
const config& get_config() const { return cfg_; }
|
||||||
|
|
||||||
|
|
|
@ -82,8 +82,8 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int do_compare(const formula_callable* other) const {
|
int do_compare(const formula_callable& other) const {
|
||||||
const lua_callable* lua = dynamic_cast<const lua_callable*>(other);
|
const lua_callable* lua = dynamic_cast<const lua_callable*>(&other);
|
||||||
if(lua == nullptr) {
|
if(lua == nullptr) {
|
||||||
return formula_callable::do_compare(other);
|
return formula_callable::do_compare(other);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue