Permalink
Browse files

PARALLACTION: Replace use of strdup with Common::String & malloc

  • Loading branch information...
csnover authored and ccawley2011 committed Dec 20, 2017
1 parent 2abc8a4 commit c263883825df3c2b5aaaedde7eb304b61093f09c
@@ -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();
@@ -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());
}


@@ -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());
}


@@ -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);
}


@@ -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);
}


@@ -234,7 +234,7 @@ DECLARE_COMMAND_OPCODE(get) {


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


@@ -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() {
@@ -53,7 +45,7 @@ void GfxObj::release() {
}

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

uint GfxObj::getNum() {
@@ -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"

@@ -286,7 +287,7 @@ enum {
};

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

public:
@@ -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();
}
@@ -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) {
@@ -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) {
@@ -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;
@@ -132,7 +131,7 @@ struct Command {
int _zeta1;
int _zeta2;
int _characterId;
char* _string2;
Common::String _string2;
int _musicCommand;
int _musicParm;
};
@@ -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 {
@@ -474,7 +471,7 @@ struct Animation : public Zone {
public:

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

Animation();
virtual ~Animation();
@@ -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);
@@ -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());
}
}

@@ -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 {
@@ -82,7 +77,7 @@ class LocationName {
}

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

@@ -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, ".");
@@ -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),
@@ -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());
}
}

@@ -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;
@@ -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();
@@ -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++;
}

@@ -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;

@@ -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];
}


@@ -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();
@@ -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);

0 comments on commit c263883

Please sign in to comment.