Skip to content

Commit

Permalink
Fixed a null pointer exception, found by Ghabry
Browse files Browse the repository at this point in the history
  • Loading branch information
MakoInfused committed Nov 9, 2024
1 parent 4d3feae commit 0ba00c4
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/game_interpreter_battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ enum BranchBattleSubcommand {
eOptionBranchBattleElse = 1
};

enum TargetType {
Actor,
Member,
Enemy,
};

static const char* target_text[] = { "actor", "party member", "enemy" };

static const void MissingTargetWarning(char* command_name, TargetType target_type, int target_id) {
Output::Warning("{}: Invalid {} ID: {}", command_name, target_text[target_type], target_id);
}

Game_Interpreter_Battle::Game_Interpreter_Battle(Span<const lcf::rpg::TroopPage> pages)
: Game_Interpreter(true), pages(pages), executed(pages.size(), false)
{
Expand Down Expand Up @@ -624,10 +636,16 @@ bool Game_Interpreter_Battle::CommandManiacControlAtbGauge(lcf::rpg::EventComman
// percentage
return (int) ((double)value / 100 * Game_Battler::GetMaxAtbGauge());
break;
default: return 0;
}
};

auto executeOperation = [getAtbValue, operand_flags](int flags, Game_Battler* battler) {
auto executeOperation = [getAtbValue, operand_flags, target_id](int flags, Game_Battler* battler, TargetType battler_type) {
if (!battler) {
MissingTargetWarning("CommandManiacControlAtbGauge", battler_type, target_id);

Check warning on line 645 in src/game_interpreter_battle.cpp

View workflow job for this annotation

GitHub Actions / ubuntu:22.04

ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

Check warning on line 645 in src/game_interpreter_battle.cpp

View workflow job for this annotation

GitHub Actions / debian:12

ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
return;
}

switch (flags) {
case 0:
// set
Expand All @@ -648,29 +666,29 @@ bool Game_Interpreter_Battle::CommandManiacControlAtbGauge(lcf::rpg::EventComman
case 0:
// actor
if (target_id > 0) {
executeOperation(operation_flags, Main_Data::game_actors->GetActor(target_id));
executeOperation(operation_flags, Main_Data::game_actors->GetActor(target_id), Actor);
}
break;
case 1:
// party member
executeOperation(operation_flags, Main_Data::game_party->GetActor(target_id));
executeOperation(operation_flags, Main_Data::game_party->GetActor(target_id), Member);
break;
case 2:
// entire party
for (Game_Battler* member : Main_Data::game_party->GetActors()) {
executeOperation(operation_flags, member);
executeOperation(operation_flags, member, Member);
}
break;
case 3:
// troop member
if (target_id > 0) {
executeOperation(operation_flags, Main_Data::game_enemyparty->GetEnemy(target_id));
executeOperation(operation_flags, Main_Data::game_enemyparty->GetEnemy(target_id), Enemy);
}
break;
case 4:
// entire troop
for (Game_Battler* member : Main_Data::game_enemyparty->GetEnemies()) {
executeOperation(operation_flags, member);
executeOperation(operation_flags, member, Enemy);
}
break;
}
Expand Down

0 comments on commit 0ba00c4

Please sign in to comment.