Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion code/menuui/readyroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,8 @@ int readyroom_continue_campaign()
{
// check for possible mission loop, need to do this before calling mission_campaign_next_mission()!
if ( !(Game_mode & GM_MULTIPLAYER) && !Campaign.loop_enabled && (Campaign.current_mission == -1) &&
(Campaign.prev_mission != -1) && (Campaign.next_mission != -1) )
(Campaign.prev_mission >= 0) && (Campaign.prev_mission < Campaign.num_missions) &&
(Campaign.next_mission != -1) )
{
if (Campaign.missions[Campaign.prev_mission].flags & CMISSION_FLAG_HAS_LOOP) {
// NOTE: the order of these calls is *very* important
Expand Down
16 changes: 11 additions & 5 deletions code/pilotfile/BinaryFileHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ Section pilot::BinaryFileHandler::nextSection() {
if (size == 0) {
return Section::Invalid;
}
if (size > static_cast<size_t>(cfilelength(_cfp)) - static_cast<size_t>(cftell(_cfp))) {
mprintf(("PLR => WARNING: Section runs past the end of the file.\n"));
return Section::Invalid;
}

_section_start_pos = (size_t)cftell(_cfp);
_section_end_pos = _section_start_pos + size;
Expand All @@ -167,11 +171,10 @@ size_t pilot::BinaryFileHandler::startArrayRead(const char*, bool short_index) {
Assertion(!_in_array, "Array nesting is not supported!");

_in_array = true;
if (short_index) {
return (size_t) cfread_short(_cfp);
} else {
return (size_t) cfread_int(_cfp);
}
auto count = short_index ? (size_t)cfread_short(_cfp) : (size_t)cfread_int(_cfp);

// every array element takes at least one byte, so a larger count has no data behind it
return std::min(count, static_cast<size_t>(cfilelength(_cfp)) - static_cast<size_t>(cftell(_cfp)));
}
void pilot::BinaryFileHandler::nextArraySection() {
Assertion(_in_array, "nextArraySection() may only be called in an array!");
Expand All @@ -182,3 +185,6 @@ void pilot::BinaryFileHandler::endArrayRead() {

_in_array = false;
}
bool pilot::BinaryFileHandler::atEndOfFile() {
return cfeof(_cfp) != 0;
}
2 changes: 2 additions & 0 deletions code/pilotfile/BinaryFileHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class BinaryFileHandler: public FileHandler {
void nextArraySection() override;

void endArrayRead() override;

bool atEndOfFile() override;
};
}

Expand Down
5 changes: 5 additions & 0 deletions code/pilotfile/FileHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ class FileHandler {
virtual void nextArraySection() = 0;

virtual void endArrayRead() = 0;

// only the binary format hands back empty values once its data has run out
virtual bool atEndOfFile() {
return false;
}
};
}

Expand Down
Loading
Loading