-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sanity checks to all LCF data structure access #1259
Conversation
src/game_actor.cpp
Outdated
* | ||
* Data::items (but not skills of items!) | ||
* | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have to update this comment
src/game_actor.cpp
Outdated
int final_level = Data::actors[actor_id - 1].final_level; | ||
exp_list.resize(final_level, 0);; | ||
for (int i = 1; i < final_level; ++i) { | ||
exp_list.resize(99); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic number, maybe use GetMaxLevel()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this looks safe because GetLevel() is sanitized.
src/game_actor.cpp
Outdated
} | ||
|
||
int Game_Actor::SetEquipment(int equip_type, int new_item_id) { | ||
if (equip_type <= 0 || equip_type > (int) GetData().equipped.size()) | ||
return -1; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stray newline
src/game_actor.cpp
Outdated
@@ -583,7 +607,7 @@ int Game_Actor::GetLevel() const { | |||
} | |||
|
|||
int Game_Actor::GetMaxLevel() const { | |||
return Data::actors[actor_id - 1].final_level; | |||
return std::max(1, std::min(GetActor().final_level, Player::IsRPG2k() ? 50 : 99)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic numbers, maybe we should add max_actor_level_*
constants.
src/game_actor.cpp
Outdated
|
||
float bottom = top; | ||
if (terrain) { | ||
bottom = top + terrain->grid_b; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ 13
is missing from old code.
src/game_battler.cpp
Outdated
const RPG::State& state = *ReaderUtil::GetElement(Data::states, i); | ||
|
||
if (state.affect_agility) { | ||
n = AffectParameter(state.affect_agility, base_agi); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was affect_type
before, wrong?
Fixed the reported problems and found more problems in the code. |
src/window_battlestatus.cpp
Outdated
@@ -102,6 +103,7 @@ void Window_BattleStatus::RefreshGauge() { | |||
} | |||
|
|||
for (int i = 0; i < item_max; ++i) { | |||
// The always only contains valid battlers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
who?
Looks good to me now apart from a few language issues in the comments, but this does not really matter. Not going to merge this, until at least a second review is available 😁. |
And that review should take at least 30 minutes ;) |
src/game_actor.cpp
Outdated
@@ -18,6 +18,7 @@ | |||
// Headers | |||
#include <algorithm> | |||
#include <sstream> | |||
#include <reader_util.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other places use quotes for liblcf includes. (2)
src/game_battle.cpp
Outdated
@@ -18,6 +18,7 @@ | |||
#include <algorithm> | |||
#include <cassert> | |||
#include <deque> | |||
#include <reader_util.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other places use quotes for liblcf includes. (3)
@@ -25,6 +25,8 @@ | |||
#include "background.h" | |||
#include "bitmap.h" | |||
#include "main_data.h" | |||
#include "reader_util.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other places use quotes for liblcf includes. (1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed all your notes except this one because it already uses quotes
src/game_battlealgorithm.cpp
Outdated
@@ -20,6 +20,7 @@ | |||
#include <cstdlib> | |||
#include <algorithm> | |||
#include <sstream> | |||
#include <reader_util.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other places use quotes for liblcf includes. (4)
src/game_commonevent.cpp
Outdated
@@ -16,6 +16,7 @@ | |||
*/ | |||
|
|||
// Headers | |||
#include <reader_util.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other places use quotes for liblcf includes. (5)
src/window_shopparty.cpp
Outdated
@@ -16,11 +16,13 @@ | |||
*/ | |||
|
|||
// Headers | |||
#include <reader_util.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other places use quotes for liblcf includes. (27)
src/window_shopsell.cpp
Outdated
@@ -18,12 +18,18 @@ | |||
// Headers | |||
#include <iomanip> | |||
#include <sstream> | |||
#include <reader_util.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other places use quotes for liblcf includes. (28)
src/window_skill.cpp
Outdated
@@ -18,6 +18,7 @@ | |||
// Headers | |||
#include <iomanip> | |||
#include <sstream> | |||
#include <reader_util.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other places use quotes for liblcf includes. (29)
src/window_targetstatus.cpp
Outdated
@@ -17,6 +17,7 @@ | |||
|
|||
// Headers | |||
#include <sstream> | |||
#include <reader_util.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other places use quotes for liblcf includes. (30)
src/game_battler.cpp
Outdated
@@ -19,6 +19,7 @@ | |||
#include <algorithm> | |||
#include <cassert> | |||
#include <cmath> | |||
#include <reader_util.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other places use quotes for liblcf includes. (31)
e8f04e7
to
e0bf97f
Compare
Thx for the feedback. Do you mean braces like here: Unfortunately the braces are required here because you can't declare variables in a case without introducing a scope :/ |
Okay, did not know they were needed then. |
There seems to be a problem when returning to the gamebrowser from some games (maybe data is not cleared or cleared in the wrong order?): |
Can you telll me a game where thus can be reproduced? |
Example games: Embric, Jojo, Lavender, Mondschein |
Had to add special handling for level 0 everywhere to prevent nullptr-dereferences due to new sanity checks (guess before it read out of bounds and somehow survived). The last commit was a random find while testing Ara Fell. |
…and exploit surface. This uses a new helper function ReaderUtil::GetElement for 1-based arrays in liblcf.
thx carstene1ns
…ich is used by COLORS: Lost Memories. Replace GetData().level calls with GetLevel(). Fix EasyRPG#1248
…d or when returning to the Game Browser because Game_Screen accesses invalid picture data.
… (the state ID is the array index and the array value are the turns since the state was inflicted) the 1st check is sufficient.
…r window regains focus
Sorry for the rebase, was to prevent a future conflict. Had to remove a sanity check in "SetupBattle" because the original code has a bug and can be completely deleted. Will open an issue for this. #1314 The last unreviewed commit was: |
…nd the idle and the action animation are the same.
Well, have further investigated the reason why the message pops up: As a fix, i think clearing the party items is necessary when leaving the game, either in |
…tarted (and generated sanity check warnings in the game browser) Fix EasyRPG#1298 again
Looking forward to the bug reports. ;) |
to reduce crashes and exploit surface.