Skip to content

Commit

Permalink
NULL -> nullptr
Browse files Browse the repository at this point in the history
A few cases of NULL were missed, since changing them led to errors
(Mainly instances where it was passed to a boost::function)
  • Loading branch information
CelticMinstrel committed Mar 31, 2016
1 parent 486cf46 commit 3ac7f8d
Show file tree
Hide file tree
Showing 423 changed files with 2,380 additions and 2,390 deletions.
2 changes: 1 addition & 1 deletion projectfiles/Xcode/Mac Sources/SDLMain.mm
Expand Up @@ -108,7 +108,7 @@ int main (int argc, char **argv)
}
gArgs.push_back(argv[i]);
}
gArgs.push_back(NULL);
gArgs.push_back(nullptr);

[SDLApplication sharedApplication];
[NSBundle loadNibNamed:@"SDLMain" owner:NSApp];
Expand Down
10 changes: 5 additions & 5 deletions src/SDL_SavePNG/savepng.cpp
Expand Up @@ -73,16 +73,16 @@ int SDL_SavePNG_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst)
/* Initialize and do basic error checking */
if (!dst)
{
SDL_SetError("Argument 2 to SDL_SavePNG_RW can't be NULL, expecting SDL_RWops*\n");
SDL_SetError("Argument 2 to SDL_SavePNG_RW can't be nullptr, expecting SDL_RWops*\n");
return (SAVEPNG_ERROR);
}
if (!surface)
{
SDL_SetError("Argument 1 to SDL_SavePNG_RW can't be NULL, expecting SDL_Surface*\n");
SDL_SetError("Argument 1 to SDL_SavePNG_RW can't be nullptr, expecting SDL_Surface*\n");
if (freedst) SDL_RWclose(dst);
return (SAVEPNG_ERROR);
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, png_error_SDL, NULL); /* err_ptr, err_fn, warn_fn */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, png_error_SDL, nullptr); /* err_ptr, err_fn, warn_fn */
if (!png_ptr)
{
SDL_SetError("Unable to png_create_write_struct on %s\n", PNG_LIBPNG_VER_STRING);
Expand All @@ -93,7 +93,7 @@ int SDL_SavePNG_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst)
if (!info_ptr)
{
SDL_SetError("Unable to png_create_info_struct\n");
png_destroy_write_struct(&png_ptr, NULL);
png_destroy_write_struct(&png_ptr, nullptr);
if (freedst) SDL_RWclose(dst);
return (SAVEPNG_ERROR);
}
Expand All @@ -105,7 +105,7 @@ int SDL_SavePNG_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst)
}

/* Setup our RWops writer */
png_set_write_fn(png_ptr, dst, png_write_SDL, NULL); /* w_ptr, write_fn, flush_fn */
png_set_write_fn(png_ptr, dst, png_write_SDL, nullptr); /* w_ptr, write_fn, flush_fn */

/* Prepare chunks */
colortype = PNG_COLOR_MASK_COLOR;
Expand Down
9 changes: 4 additions & 5 deletions src/about.cpp
Expand Up @@ -40,7 +40,6 @@
#include <algorithm> // for max
#include <boost/foreach.hpp> // for auto_any_base, etc
#include <boost/scoped_ptr.hpp> // for scoped_ptr
#include <cstddef> // for NULL
#include <map> // for map, map<>::mapped_type
#include <ostream> // for operator<<, basic_ostream, etc

Expand Down Expand Up @@ -211,7 +210,7 @@ void show_about(CVideo &video, const std::string &campaign)
{
boost::scoped_ptr<cursor::setter> cur(new cursor::setter(cursor::WAIT));
surface& screen = video.getSurface();
if (screen == NULL) return;
if (screen == nullptr) return;

// If the title is multi-line, we need to split it accordingly or we
// get slight scrolling glitches in the credits screen.
Expand Down Expand Up @@ -350,14 +349,14 @@ void show_about(CVideo &video, const std::string &campaign)

if (redraw_mapimage) {
// draw map to screen, thus erasing all text
sdl_blit(map_image_scaled, NULL, screen, NULL);
sdl_blit(map_image_scaled, nullptr, screen, nullptr);
update_rect(screen_rect);

// redraw the dialog
f.draw_background();
f.draw_border();
// cache the dialog background (alpha blending + blurred map)
sdl_blit(screen, &text_rect, text_surf, NULL);
sdl_blit(screen, &text_rect, text_surf, nullptr);
redraw_mapimage = false;
} else {
// redraw the saved part of the dialog where text scrolled
Expand Down Expand Up @@ -385,7 +384,7 @@ void show_about(CVideo &video, const std::string &campaign)
// since the real drawing on screen is clipped,
// we do a dummy one to get the height of the not clipped line.
// (each time because special format characters may change it)
const int line_height = font::draw_text(NULL, text_rect, def_size, def_color,
const int line_height = font::draw_text(nullptr, text_rect, def_size, def_color,
text[line], 0,0).h;

if(is_new_line) {
Expand Down
66 changes: 33 additions & 33 deletions src/actions/attack.cpp
Expand Up @@ -71,7 +71,7 @@ battle_context_unit_stats::battle_context_unit_stats(const unit &u,
const map_location& u_loc, int u_attack_num, bool attacking,
const unit &opp, const map_location& opp_loc,
const attack_type *opp_weapon, const unit_map& units) :
weapon(NULL),
weapon(nullptr),
attack_num(u_attack_num),
is_attacker(attacking),
is_poisoned(u.get_state(unit::STATE_POISONED)),
Expand Down Expand Up @@ -323,8 +323,8 @@ battle_context::battle_context(const unit_map& units,
const map_location& attacker_loc, const map_location& defender_loc,
int attacker_weapon, int defender_weapon, double aggression,
const combatant *prev_def, const unit* attacker_ptr) :
attacker_stats_(NULL), defender_stats_(NULL), attacker_combatant_(NULL),
defender_combatant_(NULL)
attacker_stats_(nullptr), defender_stats_(nullptr), attacker_combatant_(nullptr),
defender_combatant_(nullptr)
{
const unit &attacker = attacker_ptr ? *attacker_ptr : *units.find(attacker_loc);
const unit &defender = *units.find(defender_loc);
Expand All @@ -344,8 +344,8 @@ battle_context::battle_context(const unit_map& units,

// If those didn't have to generate statistics, do so now.
if (!attacker_stats_) {
const attack_type *adef = NULL;
const attack_type *ddef = NULL;
const attack_type *adef = nullptr;
const attack_type *ddef = nullptr;
if (attacker_weapon >= 0) {
VALIDATE(attacker_weapon < static_cast<int>(attacker.attacks().size()),
_("An invalid attacker weapon got selected."));
Expand All @@ -372,14 +372,14 @@ battle_context::battle_context(const battle_context_unit_stats &att,
const battle_context_unit_stats &def) :
attacker_stats_(new battle_context_unit_stats(att)),
defender_stats_(new battle_context_unit_stats(def)),
attacker_combatant_(NULL),
defender_combatant_(NULL)
attacker_combatant_(nullptr),
defender_combatant_(nullptr)
{
}

battle_context::battle_context(const battle_context &other) :
attacker_stats_(NULL), defender_stats_(NULL), attacker_combatant_(NULL),
defender_combatant_(NULL)
attacker_stats_(nullptr), defender_stats_(nullptr), attacker_combatant_(nullptr),
defender_combatant_(nullptr)
{
*this = other;
}
Expand All @@ -401,8 +401,8 @@ battle_context& battle_context::operator=(const battle_context &other)
delete defender_combatant_;
attacker_stats_ = new battle_context_unit_stats(*other.attacker_stats_);
defender_stats_ = new battle_context_unit_stats(*other.defender_stats_);
attacker_combatant_ = other.attacker_combatant_ ? new combatant(*other.attacker_combatant_, *attacker_stats_) : NULL;
defender_combatant_ = other.defender_combatant_ ? new combatant(*other.defender_combatant_, *defender_stats_) : NULL;
attacker_combatant_ = other.attacker_combatant_ ? new combatant(*other.attacker_combatant_, *attacker_stats_) : nullptr;
defender_combatant_ = other.defender_combatant_ ? new combatant(*other.defender_combatant_, *defender_stats_) : nullptr;
}
return *this;
}
Expand Down Expand Up @@ -491,12 +491,12 @@ int battle_context::choose_attacker_weapon(const unit &attacker,
if (choices.size() == 1) {
*defender_weapon = choose_defender_weapon(attacker, defender, choices[0], units,
attacker_loc, defender_loc, prev_def);
const attack_type *def_weapon = *defender_weapon >= 0 ? &defender.attacks()[*defender_weapon] : NULL;
const attack_type *def_weapon = *defender_weapon >= 0 ? &defender.attacks()[*defender_weapon] : nullptr;
attacker_stats_ = new battle_context_unit_stats(attacker, attacker_loc, choices[0],
true, defender, defender_loc, def_weapon, units);
if (attacker_stats_->disable) {
delete attacker_stats_;
attacker_stats_ = NULL;
attacker_stats_ = nullptr;
return -1;
}
const attack_type &att = attacker.attacks()[choices[0]];
Expand All @@ -506,24 +506,24 @@ int battle_context::choose_attacker_weapon(const unit &attacker,
}

// Multiple options: simulate them, save best.
battle_context_unit_stats *best_att_stats = NULL, *best_def_stats = NULL;
combatant *best_att_comb = NULL, *best_def_comb = NULL;
battle_context_unit_stats *best_att_stats = nullptr, *best_def_stats = nullptr;
combatant *best_att_comb = nullptr, *best_def_comb = nullptr;

for (i = 0; i < choices.size(); ++i) {
const attack_type &att = attacker.attacks()[choices[i]];
int def_weapon = choose_defender_weapon(attacker, defender, choices[i], units,
attacker_loc, defender_loc, prev_def);
// If that didn't simulate, do so now.
if (!attacker_combatant_) {
const attack_type *def = NULL;
const attack_type *def = nullptr;
if (def_weapon >= 0) {
def = &defender.attacks()[def_weapon];
}
attacker_stats_ = new battle_context_unit_stats(attacker, attacker_loc, choices[i],
true, defender, defender_loc, def, units);
if (attacker_stats_->disable) {
delete attacker_stats_;
attacker_stats_ = NULL;
attacker_stats_ = nullptr;
continue;
}
defender_stats_ = new battle_context_unit_stats(defender, defender_loc, def_weapon, false,
Expand All @@ -548,10 +548,10 @@ int battle_context::choose_attacker_weapon(const unit &attacker,
delete attacker_stats_;
delete defender_stats_;
}
attacker_combatant_ = NULL;
defender_combatant_ = NULL;
attacker_stats_ = NULL;
defender_stats_ = NULL;
attacker_combatant_ = nullptr;
defender_combatant_ = nullptr;
attacker_stats_ = nullptr;
defender_stats_ = nullptr;
}

attacker_combatant_ = best_att_comb;
Expand Down Expand Up @@ -792,9 +792,9 @@ namespace {

attack::attack(const map_location &attacker, const map_location &defender,
int attack_with, int defend_with, bool update_display) :
bc_(NULL),
a_stats_(NULL),
d_stats_(NULL),
bc_(nullptr),
a_stats_(nullptr),
d_stats_(nullptr),
abs_n_attack_(0),
abs_n_defend_(0),
update_att_fog_(false),
Expand All @@ -821,10 +821,10 @@ namespace {
config ev_data;
config& a_weapon_cfg = ev_data.add_child("first");
config& d_weapon_cfg = ev_data.add_child("second");
if(a_stats_->weapon != NULL && a_.valid()) {
if(a_stats_->weapon != nullptr && a_.valid()) {
a_stats_->weapon->write(a_weapon_cfg);
}
if(d_stats_->weapon != NULL && d_.valid()) {
if(d_stats_->weapon != nullptr && d_.valid()) {
d_stats_->weapon->write(d_weapon_cfg);
}
if(a_weapon_cfg["name"].empty()) {
Expand Down Expand Up @@ -869,11 +869,11 @@ namespace {
// Fix pointer to weapons
const_cast<battle_context_unit_stats*>(a_stats_)->weapon =
a_.valid() && a_.weapon_ >= 0
? &a_.get_unit().attacks()[a_.weapon_] : NULL;
? &a_.get_unit().attacks()[a_.weapon_] : nullptr;

const_cast<battle_context_unit_stats*>(d_stats_)->weapon =
d_.valid() && d_.weapon_ >= 0
? &d_.get_unit().attacks()[d_.weapon_] : NULL;
? &d_.get_unit().attacks()[d_.weapon_] : nullptr;

return;
}
Expand Down Expand Up @@ -1119,7 +1119,7 @@ namespace {

if (!attacker.valid()) {
unit_display::unit_die(defender.loc_, defender.get_unit(),
NULL, defender_stats->weapon);
nullptr, defender_stats->weapon);
} else {
unit_display::unit_die(defender.loc_, defender.get_unit(),
attacker_stats->weapon, defender_stats->weapon,
Expand Down Expand Up @@ -1310,8 +1310,8 @@ namespace {
u.set_experience(u.experience() + d_.xp_);
}

unit_display::unit_sheath_weapon(a_.loc_,a_.valid()?&a_.get_unit():NULL,a_stats_->weapon,
d_stats_->weapon,d_.loc_,d_.valid()?&d_.get_unit():NULL);
unit_display::unit_sheath_weapon(a_.loc_,a_.valid()?&a_.get_unit():nullptr,a_stats_->weapon,
d_stats_->weapon,d_.loc_,d_.valid()?&d_.get_unit():nullptr);

if (update_display_){
resources::screen->invalidate_unit();
Expand Down Expand Up @@ -1427,7 +1427,7 @@ namespace

//if ai_advancement_ is the default advancement the following code will
//have no effect because get_advancements returns an empty list.
if(ai_advancement_ != NULL)
if(ai_advancement_ != nullptr)
{
unit_map::iterator u = resources::units->find(loc_);
const std::vector<std::string>& options = u->advances_to();
Expand Down Expand Up @@ -1604,7 +1604,7 @@ void advance_unit(map_location loc, const std::string &advance_to,
std::vector<int> not_seeing = actions::get_sides_not_seeing(*u);

// Create the advanced unit.
bool use_amla = mod_option != NULL;
bool use_amla = mod_option != nullptr;
unit_ptr new_unit = use_amla ? get_amla_unit(*u, *mod_option) :
get_advanced_unit(*u, advance_to);
if ( !use_amla )
Expand Down
20 changes: 10 additions & 10 deletions src/actions/attack.hpp
Expand Up @@ -48,7 +48,7 @@ inline unsigned swarm_blows(unsigned min_blows, unsigned max_blows, unsigned hp,
/** Structure describing the statistics of a unit involved in the battle. */
struct battle_context_unit_stats
{
const attack_type *weapon; /**< The weapon used by the unit to attack the opponent, or NULL if there is none. */
const attack_type *weapon; /**< The weapon used by the unit to attack the opponent, or nullptr if there is none. */
int attack_num; /**< Index into unit->attacks() or -1 for none. */
bool is_attacker; /**< True if the unit is the attacker. */
bool is_poisoned; /**< True if the unit is poisoned at the beginning of the battle. */
Expand Down Expand Up @@ -109,7 +109,7 @@ struct battle_context_unit_stats
battle_context_unit_stats(int dmg, int blows, int hitpoints, int maximum_hp,
int hit_chance, bool drain, bool slows, bool slowed,
bool berserk, bool first, bool do_swarm) :
weapon(NULL), attack_num(0), is_attacker(true), // These are not used in attack prediction.
weapon(nullptr), attack_num(0), is_attacker(true), // These are not used in attack prediction.
is_poisoned(false), is_slowed(slowed),
slows(slows), drains(drain), petrifies(false), plagues(false),
poisons(false), backstab_pos(false), swarm(do_swarm), firststrike(first), disable(false),
Expand Down Expand Up @@ -145,8 +145,8 @@ class battle_context
battle_context(const unit_map &units,
const map_location& attacker_loc, const map_location& defender_loc,
int attacker_weapon = -1, int defender_weapon = -1,
double aggression = 0.0, const combatant *prev_def = NULL,
const unit* attacker_ptr=NULL);
double aggression = 0.0, const combatant *prev_def = nullptr,
const unit* attacker_ptr=nullptr);

/** Used by the AI which caches battle_context_unit_stats */
battle_context(const battle_context_unit_stats &att, const battle_context_unit_stats &def);
Expand All @@ -163,8 +163,8 @@ class battle_context
const battle_context_unit_stats& get_defender_stats() const { return *defender_stats_; }

/** Get the simulation results. */
const combatant &get_attacker_combatant(const combatant *prev_def = NULL);
const combatant &get_defender_combatant(const combatant *prev_def = NULL);
const combatant &get_attacker_combatant(const combatant *prev_def = nullptr);
const combatant &get_defender_combatant(const combatant *prev_def = nullptr);

/** Given this harm_weight, is this attack better than that? */
bool better_attack(class battle_context &that, double harm_weight);
Expand Down Expand Up @@ -213,7 +213,7 @@ void attack_unit_and_advance(const map_location &attacker, const map_location &d
*/
struct advance_unit_params
{
advance_unit_params(const map_location& loc) : loc_(loc), ai_advancements_(NULL), force_dialog_(false), fire_events_(true), animate_(true) {}
advance_unit_params(const map_location& loc) : loc_(loc), ai_advancements_(nullptr), force_dialog_(false), fire_events_(true), animate_(true) {}
advance_unit_params& ai_advancements(const ai::unit_advancements_aspect& value) {ai_advancements_ = &value; return *this;}
advance_unit_params& force_dialog(bool value) {force_dialog_ = value; return *this;}
advance_unit_params& fire_events(bool value) {fire_events_ = value; return *this;}
Expand Down Expand Up @@ -245,17 +245,17 @@ unit_ptr get_amla_unit(const unit &u, const config &mod_option);
* that we're going to delete, since deletion would invalidate the reference.
*/
void advance_unit(map_location loc, const std::string &advance_to,
const bool &fire_event = true, const config * mod_option = NULL);
const bool &fire_event = true, const config * mod_option = nullptr);

/**
* function which tests if the unit at loc is currently affected by leadership.
* (i.e. has a higher-level 'leadership' unit next to it).
* If it does, then the location of the leader unit will be returned,
* Otherwise map_location::null_location() will be returned.
* If 'bonus' is not NULL, the % bonus will be stored in it.
* If 'bonus' is not nullptr, the % bonus will be stored in it.
*/
map_location under_leadership(const unit_map& units, const map_location& loc,
int* bonus=NULL);
int* bonus=nullptr);

/**
* Returns the amount that a unit's damage should be multiplied by
Expand Down

0 comments on commit 3ac7f8d

Please sign in to comment.