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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/audio_generic.cpp
Expand Up @@ -67,13 +67,17 @@ void GenericAudio::BGM_Play(const std::string& file, int volume, int pitch, int

void GenericAudio::BGM_Pause() {
for (unsigned i = 0; i < nr_of_bgm_channels; i++) {
BGM_Channels[i].paused = true;
if (BGM_Channels[i].decoder) {
BGM_Channels[i].paused = true;
}
}
}

void GenericAudio::BGM_Resume() {
for (unsigned i = 0; i < nr_of_bgm_channels; i++) {
BGM_Channels[i].paused = false;
if (BGM_Channels[i].decoder) {
BGM_Channels[i].paused = false;
}
}
}

Expand Down Expand Up @@ -195,6 +199,7 @@ bool GenericAudio::PlayOnChannel(BgmChannel& chan, const std::string& file, int
return true;
} else {
Output::Warning("Couldn't play BGM %s. Format not supported", FileFinder::GetPathInsideGamePath(file).c_str());
chan.decoder.reset();
fclose(filehandle);
}

Expand Down
29 changes: 18 additions & 11 deletions src/background.cpp
Expand Up @@ -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

#include "output.h"

Background::Background(const std::string& name) :
visible(true),
Expand All @@ -47,33 +49,38 @@ Background::Background(int terrain_id) :

Graphics::RegisterDrawable(this);

const RPG::Terrain& terrain = Data::terrains[terrain_id - 1];
const RPG::Terrain* terrain = ReaderUtil::GetElement(Data::terrains, terrain_id);

if (!terrain) {
Output::Warning("Background: Invalid terrain ID %d", terrain_id);
return;
}

// Either background or frame
if (terrain.background_type == RPG::Terrain::BGAssociation_background && !terrain.background_name.empty()) {
FileRequestAsync* request = AsyncHandler::RequestFile("Backdrop", terrain.background_name);
if (terrain->background_type == RPG::Terrain::BGAssociation_background && !terrain->background_name.empty()) {
FileRequestAsync* request = AsyncHandler::RequestFile("Backdrop", terrain->background_name);
request_id = request->Bind(&Background::OnBackgroundGraphicReady, this);
request->Start();
return;
}

// Frame
if (!terrain.background_a_name.empty()) {
FileRequestAsync* request = AsyncHandler::RequestFile("Frame", terrain.background_a_name);
if (!terrain->background_a_name.empty()) {
FileRequestAsync* request = AsyncHandler::RequestFile("Frame", terrain->background_a_name);
request_id = request->Bind(&Background::OnBackgroundGraphicReady, this);
request->Start();

bg_hscroll = terrain.background_a_scrollh ? terrain.background_a_scrollh_speed : 0;
bg_vscroll = terrain.background_a_scrollv ? terrain.background_a_scrollv_speed : 0;
bg_hscroll = terrain->background_a_scrollh ? terrain->background_a_scrollh_speed : 0;
bg_vscroll = terrain->background_a_scrollv ? terrain->background_a_scrollv_speed : 0;
}

if (terrain.background_b && !terrain.background_b_name.empty()) {
FileRequestAsync* request = AsyncHandler::RequestFile("Frame", terrain.background_b_name);
if (terrain->background_b && !terrain->background_b_name.empty()) {
FileRequestAsync* request = AsyncHandler::RequestFile("Frame", terrain->background_b_name);
request_id = request->Bind(&Background::OnForegroundFrameGraphicReady, this);
request->Start();

fg_hscroll = terrain.background_b_scrollh ? terrain.background_b_scrollh_speed : 0;
fg_vscroll = terrain.background_b_scrollv ? terrain.background_b_scrollv_speed : 0;
fg_hscroll = terrain->background_b_scrollh ? terrain->background_b_scrollh_speed : 0;
fg_vscroll = terrain->background_b_scrollv ? terrain->background_b_scrollv_speed : 0;
}
}

Expand Down