Skip to content

Commit

Permalink
BLADERUNNER: Fixed few Coverity issues
Browse files Browse the repository at this point in the history
  • Loading branch information
peterkohaut committed Feb 1, 2018
1 parent 2e74fd8 commit 7f53a0c
Show file tree
Hide file tree
Showing 28 changed files with 253 additions and 74 deletions.
29 changes: 28 additions & 1 deletion engines/bladerunner/actor.cpp
Expand Up @@ -55,6 +55,33 @@ Actor::Actor(BladeRunnerEngine *vm, int actorId) {
_combatInfo = new ActorCombat(vm);

_friendlinessToOther = new int[_vm->_gameInfo->getActorCount()];

_isMoving = false;
_isTargetable = false;
_inCombat = false;
_isInvisible = false;
_isImmuneToObstacles = false;
_damageAnimIfMoving = false;
_movementTrackPaused = false;
_movementTrackNextWaypointId = -1;
_movementTrackNextDelay = -1;
_movementTrackNextAngle = -1;
_movementTrackNextRunning = false;
_movementTrackWalkingToWaypointId = -1;
_movementTrackDelayOnNextWaypoint = -1;
_width = 0;
_height = 0;
_animationMode = -1;
_animationModeCombatIdle = -1;
_animationModeCombatWalk = -1;
_animationModeCombatRun = -1;
_fps = 0;
_frame_ms = 0;
_animationId = 0;
_animationFrame = 0;
_retiredWidth = 0;
_retiredHeight = 0;
_scale = 0.0f;
}

Actor::~Actor() {
Expand Down Expand Up @@ -101,7 +128,7 @@ void Actor::setup(int actorId) {
_timersStart[i] = _vm->getTotalPlayTime();
}

_scale = 1.0;
_scale = 1.0f;

_honesty = 50;
_intelligence = 50;
Expand Down
6 changes: 4 additions & 2 deletions engines/bladerunner/ambient_sounds.cpp
Expand Up @@ -136,7 +136,8 @@ void AmbientSounds::addLoopingSound(int sfxId, int volume, int pan, int delay) {
LoopingSound &track = _loopingSounds[i];

track.isActive = true;
strcpy(track.name, name);
strncpy(track.name, name, sizeof(track.name));
track.name[sizeof(track.name) - 1] = 0;
track.hash = hash;
track.pan = pan;
track.volume = volume;
Expand Down Expand Up @@ -318,7 +319,8 @@ void AmbientSounds::addSoundByName(
uint32 now = _vm->getTotalPlayTime();

track.isActive = true;
strcpy(track.name, name);
strncpy(track.name, name, sizeof(track.name));
track.name[sizeof(track.name) - 1] = 0;
track.hash = mix_id(name);
track.timeMin = 1000 * timeMin;
track.timeMax = 1000 * timeMax;
Expand Down
41 changes: 25 additions & 16 deletions engines/bladerunner/archive.cpp
Expand Up @@ -27,11 +27,15 @@
namespace BladeRunner {

MIXArchive::MIXArchive() {
_isTLK = false;
_entryCount = 0;
_size = 0;
}

MIXArchive::~MIXArchive() {
if (_fd.isOpen())
if (_fd.isOpen()) {
debug("~MIXArchive: fd not closed: %s", _fd.getName());
}
}

bool MIXArchive::open(const Common::String &filename) {
Expand All @@ -42,21 +46,23 @@ bool MIXArchive::open(const Common::String &filename) {

_isTLK = filename.hasSuffix(".TLK");

_entry_count = _fd.readUint16LE();
_size = _fd.readUint32LE();
_entryCount = _fd.readUint16LE();
_size = _fd.readUint32LE();

_entries.resize(_entry_count);
for (uint16 i = 0; i != _entry_count; ++i) {
_entries.resize(_entryCount);
for (uint16 i = 0; i != _entryCount; ++i) {
_entries[i].id = _fd.readSint32LE();
_entries[i].offset = _fd.readUint32LE();
_entries[i].length = _fd.readUint32LE();

if (false)
debug("%08x %-12d %-12d", _entries[i].id, _entries[i].offset, _entries[i].length);
#if BLADERUNNER_DEBUG_CONSOLE
debug("%08x %-12d %-12d", _entries[i].id, _entries[i].offset, _entries[i].length);
#endif

// Verify that the entries are sorted by id. Note that id is signed.
if (i > 0)
if (i > 0) {
assert(_entries[i].id > _entries[i - 1].id);
}
}

if (_fd.err()) {
Expand All @@ -83,8 +89,9 @@ bool MIXArchive::isOpen() const {
int32 mix_id(const Common::String &name) {
char buffer[12] = { 0 };

for (uint i = 0; i != name.size() && i < 12u; ++i)
for (uint i = 0; i != name.size() && i < 12u; ++i) {
buffer[i] = (char)toupper(name[i]);
}

uint32 id = 0;
for (int i = 0; i < 12 && buffer[i]; i += 4) {
Expand Down Expand Up @@ -118,19 +125,20 @@ int32 tlk_id(const Common::String &name) {
}

uint32 MIXArchive::indexForId(int32 id) const {
uint32 lo = 0, hi = _entry_count;
uint32 lo = 0, hi = _entryCount;

while (lo < hi) {
uint32 mid = lo + (hi - lo) / 2;

if (id > _entries[mid].id)
if (id > _entries[mid].id) {
lo = mid + 1;
else if (id < _entries[mid].id)
} else if (id < _entries[mid].id) {
hi = mid;
else
} else {
return mid;
}
}
return _entry_count;
return _entryCount;
}

Common::SeekableReadStream *MIXArchive::createReadStreamForMember(const Common::String &name) {
Expand All @@ -143,10 +151,11 @@ Common::SeekableReadStream *MIXArchive::createReadStreamForMember(const Common::

uint32 i = indexForId(id);

if (i == _entry_count)
if (i == _entryCount) {
return nullptr;
}

uint32 start = _entries[i].offset + 6 + 12 * _entry_count;
uint32 start = _entries[i].offset + 6 + 12 * _entryCount;
uint32 end = _entries[i].length + start;

return new Common::SafeSeekableSubReadStream(&_fd, start, end, DisposeAfterUse::NO);
Expand Down
2 changes: 1 addition & 1 deletion engines/bladerunner/archive.h
Expand Up @@ -46,7 +46,7 @@ class MIXArchive {
Common::File _fd;
bool _isTLK;

uint16 _entry_count;
uint16 _entryCount;
uint32 _size;

struct ArchiveEntry {
Expand Down
13 changes: 10 additions & 3 deletions engines/bladerunner/aud_stream.cpp
Expand Up @@ -28,12 +28,19 @@

namespace BladeRunner {

AudStream::AudStream(byte *data) : _cache(nullptr) {
AudStream::AudStream(byte *data) {
_hash = 0;
_cache = nullptr;

init(data);
}

AudStream::AudStream(AudioCache *cache, int32 hash)
: _cache(cache), _hash(hash) {
AudStream::AudStream(AudioCache *cache, int32 hash) {
assert(cache != nullptr);

_cache = cache;
_hash = hash;

_cache->incRef(_hash);

init(_cache->findByHash(_hash));
Expand Down
2 changes: 0 additions & 2 deletions engines/bladerunner/audio_player.h
Expand Up @@ -81,8 +81,6 @@ class AudioPlayer {
int volume;
int pan;
Audio::AudioStream *stream;

Track() : isActive(false) {}
};

BladeRunnerEngine *_vm;
Expand Down
49 changes: 49 additions & 0 deletions engines/bladerunner/bladerunner.cpp
Expand Up @@ -95,6 +95,8 @@ BladeRunnerEngine::BladeRunnerEngine(OSystem *syst, const ADGameDescription *des
_gameIsLoading = false;
_sceneIsLoading = false;

_walkingActorId = -1;

_walkSoundId = -1;
_walkSoundVolume = 0;
_walkSoundBalance = 0;
Expand Down Expand Up @@ -123,6 +125,53 @@ BladeRunnerEngine::BladeRunnerEngine(OSystem *syst, const ADGameDescription *des
default:
this->_languageCode = "E";
}

_screenEffects = nullptr;
_combat = nullptr;
_actorDialogueQueue = nullptr;
_settings = nullptr;
_itemPickup = nullptr;
_lights = nullptr;
_obstacles = nullptr;
_sceneScript = nullptr;
_gameInfo = nullptr;
_waypoints = nullptr;
_gameVars = nullptr;
_view = nullptr;
_sceneObjects = nullptr;
_gameFlags = nullptr;
_items = nullptr;
_audioMixer = nullptr;
_audioPlayer = nullptr;
_music = nullptr;
_audioSpeech = nullptr;
_ambientSounds = nullptr;
_chapters = nullptr;
_overlays = nullptr;
_zbuffer = nullptr;
_playerActor = nullptr;
_textActorNames = nullptr;
_textCrimes = nullptr;
_textClueTypes = nullptr;
_textKIA = nullptr;
_textSpinnerDestinations = nullptr;
_textVK = nullptr;
_textOptions = nullptr;
_dialogueMenu = nullptr;
_suspectsDatabase = nullptr;
_kia = nullptr;
_spinner = nullptr;
_elevator = nullptr;
_mainFont = nullptr;
_mouse = nullptr;
_sliceAnimations = nullptr;
_sliceRenderer = nullptr;
_crimesDatabase = nullptr;
_scene = nullptr;
_aiScripts = nullptr;
for (int i = 0; i != kActorCount; ++i) {
_actors[i] = nullptr;
}
}

BladeRunnerEngine::~BladeRunnerEngine() {
Expand Down
6 changes: 2 additions & 4 deletions engines/bladerunner/color.h
Expand Up @@ -32,11 +32,9 @@ struct Color {
float g;
float b;

Color() {
}
Color() : r(0.0f), g(0.0f), b(0.0f) {}

Color(float r_, float g_, float b_) : r(r_), g(g_), b(b_) {
}
Color(float r_, float g_, float b_) : r(r_), g(g_), b(b_) {}
};

struct Color256 {
Expand Down
5 changes: 4 additions & 1 deletion engines/bladerunner/crimes_database.cpp
Expand Up @@ -35,7 +35,10 @@ CrimesDatabase::CrimesDatabase(BladeRunnerEngine *vm, const char *cluesResource,
_assetTypes.resize(_crimeCount);

_cluesText = new TextResource(vm);
_cluesText->open(cluesResource);
if (!_cluesText->open(cluesResource)) {
delete _cluesText;
return;
}

for (int i = 0; i != _crimeCount; ++i) {
_crimes[i] = -1;
Expand Down
5 changes: 5 additions & 0 deletions engines/bladerunner/dialogue_menu.cpp
Expand Up @@ -46,6 +46,11 @@ DialogueMenu::DialogueMenu(BladeRunnerEngine *vm) {
assert(r);
(void)r;
}

_screenX = 0;
_screenY = 0;
_maxItemWidth = 0;
_fadeInItemIndex = 0;
}

DialogueMenu::~DialogueMenu() {
Expand Down
21 changes: 21 additions & 0 deletions engines/bladerunner/fog.cpp
Expand Up @@ -27,6 +27,27 @@
namespace BladeRunner {

Fog::Fog() {
_name[0] = 0;
_frameCount = 0;
_animatedParameters = 0;
_fogDensity = 0.0f;
_animationData = nullptr;
_m11ptr = nullptr;
_m12ptr = nullptr;
_m13ptr = nullptr;
_m14ptr = nullptr;
_m21ptr = nullptr;
_m22ptr = nullptr;
_m23ptr = nullptr;
_m24ptr = nullptr;
_m31ptr = nullptr;
_m32ptr = nullptr;
_m33ptr = nullptr;
_m34ptr = nullptr;
_parameter1 = 0.0f;
_parameter2 = 0.0f;
_parameter3 = 0.0f;
_next = nullptr;
}

Fog::~Fog() {
Expand Down
24 changes: 20 additions & 4 deletions engines/bladerunner/game_info.cpp
Expand Up @@ -31,10 +31,26 @@ namespace BladeRunner {

GameInfo::GameInfo(BladeRunnerEngine *vm) {
_vm = vm;
_sceneNames = nullptr;
_sfxTracks = nullptr;
_musicTracks = nullptr;
_outtakes = nullptr;
_sceneNames = nullptr;
_sfxTracks = nullptr;
_musicTracks = nullptr;
_outtakes = nullptr;
_actorCount = 0;
_playerId = 0;
_flagCount = 0;
_clueCount = 0;
_globalVarCount = 0;
_setNamesCount = 0;
_initialSceneId = 0;
_initialSetId = 0;
_waypointCount = 0;
_sfxTrackCount = 0;
_musicTrackCount = 0;
_outtakeCount = 0;
_crimeCount = 0;
_suspectCount = 0;
_coverWaypointCount = 0;
_fleeWaypointCount = 0;
}

GameInfo::~GameInfo() {
Expand Down
28 changes: 27 additions & 1 deletion engines/bladerunner/light.cpp
Expand Up @@ -27,7 +27,33 @@
namespace BladeRunner {

Light::Light() {
_animationData = nullptr;
_frameCount = 0;
_animated = 0;
_animationData = nullptr;
_animatedParameters = 0;
_falloffStart = 0.0f;
_falloffEnd = 0.0f;
_angleStart = 0.0f;
_angleEnd = 0.0f;
_m11ptr = nullptr;
_m12ptr = nullptr;
_m13ptr = nullptr;
_m14ptr = nullptr;
_m21ptr = nullptr;
_m22ptr = nullptr;
_m23ptr = nullptr;
_m24ptr = nullptr;
_m31ptr = nullptr;
_m32ptr = nullptr;
_m33ptr = nullptr;
_m34ptr = nullptr;
_colorRPtr = nullptr;
_colorGPtr = nullptr;
_colorBPtr = nullptr;
_falloffStartPtr = nullptr;
_falloffEndPtr = nullptr;
_angleStartPtr = nullptr;
_angleEndPtr = nullptr;
}

Light::~Light() {
Expand Down

0 comments on commit 7f53a0c

Please sign in to comment.