Skip to content

Commit

Permalink
PARALLACTION: Replace use of strdup with Common::String & malloc
Browse files Browse the repository at this point in the history
  • Loading branch information
csnover authored and ccawley2011 committed Aug 15, 2018
1 parent 2abc8a4 commit c263883
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 74 deletions.
12 changes: 6 additions & 6 deletions engines/parallaction/exec_br.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ typedef Common::Functor1Mem<ProgramContext&, void, ProgramExec_br> OpcodeV2;

extern const char *_instructionNamesRes_br[];

void Parallaction_br::setupSubtitles(char *s, char *s2, int y) {
void Parallaction_br::setupSubtitles(const char *s, const char *s2, int y) {
debugC(5, kDebugExec, "setupSubtitles(%s, %s, %i)", s, s2, y);

clearSubtitles();
Expand Down Expand Up @@ -123,7 +123,7 @@ DECLARE_COMMAND_OPCODE(location) {
_vm->_location._followerStartPosition = ctxt._cmd->_startPos2;
_vm->_location._followerStartFrame = 0;

_vm->scheduleLocationSwitch(ctxt._cmd->_string);
_vm->scheduleLocationSwitch(ctxt._cmd->_string.c_str());
}


Expand Down Expand Up @@ -172,8 +172,8 @@ DECLARE_COMMAND_OPCODE(stop) {


DECLARE_COMMAND_OPCODE(character) {
debugC(9, kDebugExec, "Parallaction_br::cmdOp_character(%s)", ctxt._cmd->_string);
_vm->changeCharacter(ctxt._cmd->_string);
debugC(9, kDebugExec, "Parallaction_br::cmdOp_character(%s)", ctxt._cmd->_string.c_str());
_vm->changeCharacter(ctxt._cmd->_string.c_str());
}


Expand Down Expand Up @@ -291,7 +291,7 @@ DECLARE_COMMAND_OPCODE(give) {


DECLARE_COMMAND_OPCODE(text) {
_vm->setupSubtitles(ctxt._cmd->_string, ctxt._cmd->_string2, ctxt._cmd->_zeta0);
_vm->setupSubtitles(ctxt._cmd->_string.c_str(), ctxt._cmd->_string2.c_str(), ctxt._cmd->_zeta0);
}


Expand Down Expand Up @@ -492,7 +492,7 @@ DECLARE_INSTRUCTION_OPCODE(print) {

DECLARE_INSTRUCTION_OPCODE(text) {
InstructionPtr inst = ctxt._inst;
_vm->setupSubtitles(inst->_text, inst->_text2, inst->_y);
_vm->setupSubtitles(inst->_text.c_str(), inst->_text2.c_str(), inst->_y);
}


Expand Down
2 changes: 1 addition & 1 deletion engines/parallaction/exec_ns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ DECLARE_COMMAND_OPCODE(get) {


DECLARE_COMMAND_OPCODE(location) {
_vm->scheduleLocationSwitch(ctxt._cmd->_string);
_vm->scheduleLocationSwitch(ctxt._cmd->_string.c_str());
}


Expand Down
14 changes: 3 additions & 11 deletions engines/parallaction/gfxbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,12 @@
namespace Parallaction {

GfxObj::GfxObj(uint objType, Frames *frames, const char* name) :
_frames(frames), x(0), y(0), z(0), _prog(0), _flags(0),
_name(name), _frames(frames), x(0), y(0), z(0), _prog(0), _flags(0),
type(objType), frame(0), layer(3), scale(100), _hasMask(false), _hasPath(false),
transparentKey(0), _maskId(0), _pathId(0) {

if (name) {
_name = strdup(name);
} else {
_name = 0;
}
}
transparentKey(0), _maskId(0), _pathId(0) {}

GfxObj::~GfxObj() {
delete _frames;
free(_name);
}

void GfxObj::release() {
Expand All @@ -53,7 +45,7 @@ void GfxObj::release() {
}

const char *GfxObj::getName() const {
return _name;
return _name.c_str();
}

uint GfxObj::getNum() {
Expand Down
3 changes: 2 additions & 1 deletion engines/parallaction/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "common/rect.h"
#include "common/hashmap.h"
#include "common/hash-str.h"
#include "common/str.h"
#include "common/stream.h"
#include "common/array.h"

Expand Down Expand Up @@ -286,7 +287,7 @@ enum {
};

class GfxObj {
char *_name;
Common::String _name;
Frames *_frames;

public:
Expand Down
22 changes: 3 additions & 19 deletions engines/parallaction/objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,24 @@ Command::Command() {
_valid = false;

_flags = 0;
_string = 0;
_callable = 0;
_object = 0;
_counterValue = 0;
_zeta0 = 0;
_zeta1 = 0;
_zeta2 = 0;
_characterId = 0;
_string2 = 0;
_musicCommand = 0;
_musicParm = 0;
}

Command::~Command() {
free(_string);
free(_string2);
}


Animation::Animation() {
gfxobj = NULL;
_scriptName = 0;
_frame = 0;
_z = 0;
}

Animation::~Animation() {
free(_scriptName);
if (gfxobj) {
gfxobj->release();
}
Expand Down Expand Up @@ -307,16 +297,9 @@ Instruction::Instruction() {
_endif = 0;

// BRA specific
_text = 0;
_text2 = 0;
_y = 0;
}

Instruction::~Instruction() {
free(_text);
free(_text2);
}

int16 ScriptVar::getValue() {

if (_flags & kParaImmediate) {
Expand Down Expand Up @@ -415,8 +398,9 @@ void Table::addData(const char* s) {
if (!(_used < _size))
error("Table overflow");

_data[_used++] = strdup(s);

char *data = (char *)malloc(strlen(s) + 1);
strcpy(data, s);
_data[_used++] = data;
}

uint16 Table::lookup(const char* s) {
Expand Down
13 changes: 5 additions & 8 deletions engines/parallaction/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,12 @@ struct Command {
bool _valid;

Command();
~Command();

// Common fields
uint32 _flags;
ZonePtr _zone;
Common::String _zoneName;
char* _string;
Common::String _string;
uint16 _callable;
uint16 _object;
Common::Point _move;
Expand All @@ -132,7 +131,7 @@ struct Command {
int _zeta1;
int _zeta2;
int _characterId;
char* _string2;
Common::String _string2;
int _musicCommand;
int _musicParm;
};
Expand Down Expand Up @@ -428,14 +427,12 @@ struct Instruction {
// BRA specific
byte _colors[3];
ScriptVar _opC;
char *_text;
char *_text2;
Common::String _text;
Common::String _text2;
int _y;
uint32 _endif;

Instruction();
~Instruction();

};

enum {
Expand Down Expand Up @@ -474,7 +471,7 @@ struct Animation : public Zone {
public:

GfxObj *gfxobj;
char *_scriptName;
Common::String _scriptName;

Animation();
virtual ~Animation();
Expand Down
2 changes: 1 addition & 1 deletion engines/parallaction/parallaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ class Parallaction_br : public Parallaction {
virtual DialogueManager *createDialogueManager(ZonePtr z);
virtual bool processGameEvent(int event);

void setupSubtitles(char *s, char *s2, int y);
void setupSubtitles(const char *s, const char *s2, int y);
void clearSubtitles();

void testCounterCondition(const Common::String &name, int op, int value);
Expand Down
4 changes: 2 additions & 2 deletions engines/parallaction/parallaction_br.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ void Parallaction_br::parseLocation(const char *filename) {
restoreOrSaveZoneFlags(*ait, visited);

// load the script
if ((*ait)->_scriptName) {
loadProgram(*ait, (*ait)->_scriptName);
if (!(*ait)->_scriptName.empty()) {
loadProgram(*ait, (*ait)->_scriptName.c_str());
}
}

Expand Down
23 changes: 7 additions & 16 deletions engines/parallaction/parallaction_ns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,14 @@ class LocationName {

bool _hasCharacter;
bool _hasSlide;
char *_buf;
Common::String _buf;

public:
LocationName() {
_buf = 0;
_hasSlide = false;
_hasCharacter = false;
}

~LocationName() {
free(_buf);
}

void bind(const char*);

const char *location() const {
Expand All @@ -82,7 +77,7 @@ class LocationName {
}

const char *c_str() const {
return _buf;
return _buf.c_str();
}
};

Expand All @@ -106,15 +101,12 @@ class LocationName {
is commented out, and would definitely crash the current implementation.
*/
void LocationName::bind(const char *s) {

free(_buf);

_buf = strdup(s);
_buf = s;
_hasSlide = false;
_hasCharacter = false;

Common::StringArray list;
char *tok = strtok(_buf, ".");
char *tok = strtok(_buf.begin(), ".");
while (tok) {
list.push_back(tok);
tok = strtok(NULL, ".");
Expand All @@ -139,8 +131,7 @@ void LocationName::bind(const char *s) {
}

_location = list[0];

strcpy(_buf, s); // kept as reference
_buf = s; // kept as reference
}

Parallaction_ns::Parallaction_ns(OSystem* syst, const PARALLACTIONGameDescription *gameDesc) : Parallaction(syst, gameDesc),
Expand Down Expand Up @@ -454,8 +445,8 @@ void Parallaction_ns::parseLocation(const char *filename) {
// this loads animation scripts
AnimationList::iterator it = _location._animations.begin();
for ( ; it != _location._animations.end(); ++it) {
if ((*it)->_scriptName) {
loadProgram(*it, (*it)->_scriptName);
if (!(*it)->_scriptName.empty()) {
loadProgram(*it, (*it)->_scriptName.c_str());
}
}

Expand Down
12 changes: 6 additions & 6 deletions engines/parallaction/parser_br.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ DECLARE_COMMAND_PARSER(location) {

createCommand(_parser->_lookup);

ctxt.cmd->_string = strdup(_tokens[1]);
ctxt.cmd->_string = _tokens[1];
ctxt.nextToken++;

ctxt.cmd->_startPos.x = -1000;
Expand Down Expand Up @@ -550,7 +550,7 @@ DECLARE_COMMAND_PARSER(string) {

createCommand(_parser->_lookup);

ctxt.cmd->_string = strdup(_tokens[1]);
ctxt.cmd->_string = _tokens[1];
ctxt.nextToken++;

parseCommandFlags();
Expand Down Expand Up @@ -685,11 +685,11 @@ DECLARE_COMMAND_PARSER(text) {
ctxt.cmd->_zeta0 = -1;
}

ctxt.cmd->_string = strdup(_tokens[ctxt.nextToken]);
ctxt.cmd->_string = _tokens[ctxt.nextToken];
ctxt.nextToken++;

if (_tokens[ctxt.nextToken][0] != '\0' && scumm_stricmp("flags", _tokens[ctxt.nextToken])) {
ctxt.cmd->_string2 = strdup(_tokens[ctxt.nextToken]);
ctxt.cmd->_string2 = _tokens[ctxt.nextToken];
ctxt.nextToken++;
}

Expand Down Expand Up @@ -1011,11 +1011,11 @@ DECLARE_INSTRUCTION_PARSER(text) {
ctxt.inst->_y = -1;
}

ctxt.inst->_text = strdup(_tokens[_si]);
ctxt.inst->_text = _tokens[_si];
_si++;

if (_tokens[_si][0] != '\0' && scumm_stricmp("flags", _tokens[_si])) {
ctxt.inst->_text2 = strdup(_tokens[_si]);
ctxt.inst->_text2 = _tokens[_si];
}
ctxt.inst->_index = _parser->_lookup;

Expand Down
4 changes: 2 additions & 2 deletions engines/parallaction/parser_ns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void LocationParser_ns::warning_unexpected() {
DECLARE_ANIM_PARSER(script) {
debugC(7, kDebugParser, "ANIM_PARSER(script) ");

ctxt.a->_scriptName = strdup(_tokens[1]);
ctxt.a->_scriptName = _tokens[1];
}


Expand Down Expand Up @@ -643,7 +643,7 @@ DECLARE_COMMAND_PARSER(location) {

createCommand(_parser->_lookup);

ctxt.cmd->_string = strdup(_tokens[ctxt.nextToken]);
ctxt.cmd->_string = _tokens[ctxt.nextToken];
ctxt.nextToken++;

parseCommandFlags();
Expand Down
2 changes: 1 addition & 1 deletion engines/parallaction/walk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ void PathWalker_BR::doWalk(State &s) {

if (s._walkDelay > 0) {
s._walkDelay--;
if (s._walkDelay == 0 && s._a->_scriptName) {
if (s._walkDelay == 0 && !s._a->_scriptName.empty()) {
// stop script and reset
s._a->_flags &= ~kFlagsActing;
// _vm->_programExec->resetProgram(s._a->_scriptName);
Expand Down

0 comments on commit c263883

Please sign in to comment.