Skip to content
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

Merged
merged 15 commits into from
Jan 2, 2018

Conversation

Ghabry
Copy link
Member

@Ghabry Ghabry commented Sep 9, 2017

to reduce crashes and exploit surface.

*
* Data::items (but not skills of items!)
*
*/
Copy link
Member Author

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

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);
Copy link
Member

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().

Copy link
Member Author

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.

}

int Game_Actor::SetEquipment(int equip_type, int new_item_id) {
if (equip_type <= 0 || equip_type > (int) GetData().equipped.size())
return -1;


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stray newline

@@ -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));
Copy link
Member

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.


float bottom = top;
if (terrain) {
bottom = top + terrain->grid_b;
Copy link
Member

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.

const RPG::State& state = *ReaderUtil::GetElement(Data::states, i);

if (state.affect_agility) {
n = AffectParameter(state.affect_agility, base_agi);
Copy link
Member

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?

@Ghabry
Copy link
Member Author

Ghabry commented Sep 20, 2017

Fixed the reported problems and found more problems in the code.
Did a new commit to make the review easier.

@@ -102,6 +103,7 @@ void Window_BattleStatus::RefreshGauge() {
}

for (int i = 0; i < item_max; ++i) {
// The always only contains valid battlers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

who?

@carstene1ns
Copy link
Member

carstene1ns commented Sep 20, 2017

Looks good to me now apart from a few language issues in the comments, but this does not really matter.
e.g.
[…] array is resized dynamically


Not going to merge this, until at least a second review is available 😁.

@Ghabry
Copy link
Member Author

Ghabry commented Sep 20, 2017

And that review should take at least 30 minutes ;)

@@ -18,6 +18,7 @@
// Headers
#include <algorithm>
#include <sstream>
#include <reader_util.h>
Copy link
Contributor

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)

@@ -18,6 +18,7 @@
#include <algorithm>
#include <cassert>
#include <deque>
#include <reader_util.h>
Copy link
Contributor

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"
Copy link
Contributor

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)

Copy link
Member Author

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

@@ -20,6 +20,7 @@
#include <cstdlib>
#include <algorithm>
#include <sstream>
#include <reader_util.h>
Copy link
Contributor

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)

@@ -16,6 +16,7 @@
*/

// Headers
#include <reader_util.h>
Copy link
Contributor

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)

@@ -16,11 +16,13 @@
*/

// Headers
#include <reader_util.h>
Copy link
Contributor

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)

@@ -18,12 +18,18 @@
// Headers
#include <iomanip>
#include <sstream>
#include <reader_util.h>
Copy link
Contributor

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)

@@ -18,6 +18,7 @@
// Headers
#include <iomanip>
#include <sstream>
#include <reader_util.h>
Copy link
Contributor

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)

@@ -17,6 +17,7 @@

// Headers
#include <sstream>
#include <reader_util.h>
Copy link
Contributor

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)

@@ -19,6 +19,7 @@
#include <algorithm>
#include <cassert>
#include <cmath>
#include <reader_util.h>
Copy link
Contributor

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)

@Ghabry Ghabry modified the milestones: 0.5.3, 0.5.4 Oct 1, 2017
@Ghabry Ghabry force-pushed the sanitycheck branch 3 times, most recently from e8f04e7 to e0bf97f Compare November 4, 2017 22:08
@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017
@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017
@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017
@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017
@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017
@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017
@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017
@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017
@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017
@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017
@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017
@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017
@Ghabry
Copy link
Member Author

Ghabry commented Nov 26, 2017

Thx for the feedback. Do you mean braces like here:
https://github.com/Ghabry/easyrpg-player/blob/5fdc7d78e07f6c8196a6f3405cfbda25c7f3c7e9/src/game_interpreter.cpp#L2823-L2830

Unfortunately the braces are required here because you can't declare variables in a case without introducing a scope :/

@carstene1ns
Copy link
Member

Okay, did not know they were needed then.

@carstene1ns
Copy link
Member

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?): Warning: Removing invalid item # from party

@Ghabry
Copy link
Member Author

Ghabry commented Nov 27, 2017

Can you telll me a game where thus can be reproduced?

@carstene1ns
Copy link
Member

Example games: Embric, Jojo, Lavender, Mondschein
To reproduce load a save or begin the game, press F12 and choose Exit in the Menu.

@Ghabry
Copy link
Member Author

Ghabry commented Nov 29, 2017

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.

@Ghabry
Copy link
Member Author

Ghabry commented Dec 6, 2017

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:
"Add exception in the sanity check and special handling for Level 0"

…nd the idle and the action animation are the same.
@carstene1ns
Copy link
Member

Well, have further investigated the reason why the message pops up:
When returning from game to title scene via F12, Data is not cleared when Player::ResetGameObjects() is called. Thus, the items are still valid. However, when returning to the gamebrowser, they are still there, but Data::Clear() has been called, so they are invalid.

As a fix, i think clearing the party items is necessary when leaving the game, either in ResetGameObjects() or where the party members are removed.

…tarted (and generated sanity check warnings in the game browser)

Fix EasyRPG#1298 again
@carstene1ns carstene1ns merged commit 34a6b9d into EasyRPG:master Jan 2, 2018
@Ghabry
Copy link
Member Author

Ghabry commented Jan 2, 2018

Looking forward to the bug reports. ;)

@Ghabry Ghabry deleted the sanitycheck branch May 7, 2018 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants