mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-19 08:25:35 +00:00
SKY: Don't use unsafe strcat and strcpy
This commit is contained in:
parent
682c11e801
commit
5b67238944
@ -288,7 +288,7 @@ Compact *SkyCompact::fetchCpt(uint16 cptId) {
|
||||
return _compacts[cptId >> 12][cptId & 0xFFF];
|
||||
}
|
||||
|
||||
Compact *SkyCompact::fetchCptInfo(uint16 cptId, uint16 *elems, uint16 *type, char *name) {
|
||||
Compact *SkyCompact::fetchCptInfo(uint16 cptId, uint16 *elems, uint16 *type, char *name, size_t nameSize) {
|
||||
assert(((cptId >> 12) < _numDataLists) && ((cptId & 0xFFF) < _dataListLen[cptId >> 12]));
|
||||
if (elems)
|
||||
*elems = _cptSizes[cptId >> 12][cptId & 0xFFF];
|
||||
@ -296,9 +296,9 @@ Compact *SkyCompact::fetchCptInfo(uint16 cptId, uint16 *elems, uint16 *type, cha
|
||||
*type = _cptTypes[cptId >> 12][cptId & 0xFFF];
|
||||
if (name) {
|
||||
if (_cptNames[cptId >> 12][cptId & 0xFFF] != NULL)
|
||||
strcpy(name, _cptNames[cptId >> 12][cptId & 0xFFF]);
|
||||
Common::strcpy_s(name, nameSize, _cptNames[cptId >> 12][cptId & 0xFFF]);
|
||||
else
|
||||
strcpy(name, "(null)");
|
||||
Common::strcpy_s(name, nameSize, "(null)");
|
||||
}
|
||||
return fetchCpt(cptId);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ public:
|
||||
SkyCompact();
|
||||
~SkyCompact();
|
||||
Compact *fetchCpt(uint16 cptId);
|
||||
Compact *fetchCptInfo(uint16 cptId, uint16 *elems = NULL, uint16 *type = NULL, char *name = NULL);
|
||||
Compact *fetchCptInfo(uint16 cptId, uint16 *elems = NULL, uint16 *type = NULL, char *name = NULL, size_t nameSize = 0);
|
||||
static uint16 getSub(Compact *cpt, uint16 mode);
|
||||
static void setSub(Compact *cpt, uint16 mode, uint16 value);
|
||||
static MegaSet *getMegaSet(Compact *cpt);
|
||||
|
@ -1423,7 +1423,7 @@ uint16 Control::parseSaveData(uint8 *srcBuf) {
|
||||
uint16 numElems;
|
||||
uint16 type;
|
||||
char name[128];
|
||||
uint16 *rawCpt = (uint16 *)_skyCompact->fetchCptInfo(_skyCompact->_saveIds[cnt], &numElems, &type, name);
|
||||
uint16 *rawCpt = (uint16 *)_skyCompact->fetchCptInfo(_skyCompact->_saveIds[cnt], &numElems, &type, name, sizeof(name));
|
||||
if (type == COMPACT) {
|
||||
importOldCompact((Compact *)rawCpt, &srcPos, numElems, type, name);
|
||||
} else if (type == ROUTEBUF) {
|
||||
|
@ -1137,7 +1137,7 @@ static const char *const noYes[] = { "no", "yes" };
|
||||
void Debugger::dumpCompact(uint16 cptId) {
|
||||
uint16 type, size;
|
||||
char name[256];
|
||||
Compact *cpt = _skyCompact->fetchCptInfo(cptId, &size, &type, name);
|
||||
Compact *cpt = _skyCompact->fetchCptInfo(cptId, &size, &type, name, sizeof(name));
|
||||
|
||||
if (type == COMPACT) {
|
||||
debugPrintf("Compact %s: id = %04X, section %d, id %d\n", name, cptId, cptId >> 12, cptId & 0xFFF);
|
||||
@ -1154,9 +1154,9 @@ void Debugger::dumpCompact(uint16 cptId) {
|
||||
debugPrintf(" : ar priority : %s\n", noYes[(cpt->status & ST_AR_PRIORITY) >> 8]);
|
||||
debugPrintf("sync : %04X\n", cpt->sync);
|
||||
debugPrintf("screen : %d\n", cpt->screen);
|
||||
_skyCompact->fetchCptInfo(cpt->place, NULL, NULL, name);
|
||||
_skyCompact->fetchCptInfo(cpt->place, NULL, NULL, name, sizeof(name));
|
||||
debugPrintf("place : %04X: %s\n", cpt->place, name);
|
||||
_skyCompact->fetchCptInfo(cpt->getToTableId, NULL, NULL, name);
|
||||
_skyCompact->fetchCptInfo(cpt->getToTableId, NULL, NULL, name, sizeof(name));
|
||||
debugPrintf("get to tab : %04X: %s\n", cpt->getToTableId, name);
|
||||
debugPrintf("x/y : %d/%d\n", cpt->xcood, cpt->ycood);
|
||||
} else {
|
||||
@ -1201,7 +1201,7 @@ bool Debugger::Cmd_ShowCompact(int argc, const char **argv) {
|
||||
uint16 cptId = (uint16)((sec << 12) | cpt);
|
||||
uint16 type, size;
|
||||
char name[256];
|
||||
_skyCompact->fetchCptInfo(cptId, &size, &type, name);
|
||||
_skyCompact->fetchCptInfo(cptId, &size, &type, name, sizeof(name));
|
||||
linePos += sprintf(linePos, "%04X: %10s %22s", cptId, _skyCompact->nameForType(type), name);
|
||||
}
|
||||
if (linePos != line)
|
||||
@ -1211,7 +1211,7 @@ bool Debugger::Cmd_ShowCompact(int argc, const char **argv) {
|
||||
uint16 cptId = (uint16)((sec << 12) | cpt);
|
||||
uint16 type, size;
|
||||
char name[256];
|
||||
_skyCompact->fetchCptInfo(cptId, &size, &type, name);
|
||||
_skyCompact->fetchCptInfo(cptId, &size, &type, name, sizeof(name));
|
||||
if (type == COMPACT)
|
||||
debugPrintf("%04X: %s\n", cptId, name);
|
||||
}
|
||||
@ -1333,15 +1333,15 @@ bool Debugger::Cmd_LogicList(int argc, const char **argv) {
|
||||
|
||||
char cptName[256];
|
||||
uint16 numElems, type;
|
||||
uint16 *logicList = (uint16 *)_skyCompact->fetchCptInfo(Logic::_scriptVariables[LOGIC_LIST_NO], &numElems, &type, cptName);
|
||||
uint16 *logicList = (uint16 *)_skyCompact->fetchCptInfo(Logic::_scriptVariables[LOGIC_LIST_NO], &numElems, &type, cptName, sizeof(cptName));
|
||||
debugPrintf("Current LogicList: %04X (%s)\n", Logic::_scriptVariables[LOGIC_LIST_NO], cptName);
|
||||
while (*logicList != 0) {
|
||||
if (*logicList == 0xFFFF) {
|
||||
uint16 newList = logicList[1];
|
||||
logicList = (uint16 *)_skyCompact->fetchCptInfo(newList, &numElems, &type, cptName);
|
||||
logicList = (uint16 *)_skyCompact->fetchCptInfo(newList, &numElems, &type, cptName, sizeof(cptName));
|
||||
debugPrintf("New List: %04X (%s)\n", newList, cptName);
|
||||
} else {
|
||||
_skyCompact->fetchCptInfo(*logicList, &numElems, &type, cptName);
|
||||
_skyCompact->fetchCptInfo(*logicList, &numElems, &type, cptName, sizeof(cptName));
|
||||
debugPrintf(" Cpt %04X (%s) (%s)\n", *logicList, cptName, _skyCompact->nameForType(type));
|
||||
logicList++;
|
||||
}
|
||||
|
@ -246,14 +246,16 @@ DisplayedText Text::displayText(char *textPtr, uint8 *dest, bool center, uint16
|
||||
// work around bug #1080 (line width exceeded)
|
||||
char *tmpPtr = strstr(textPtr, "MUND-BEATMUNG!");
|
||||
if (tmpPtr)
|
||||
strcpy(tmpPtr, "MUND BEATMUNG!");
|
||||
// We are sure there is at least this space and we replace it by something of same length
|
||||
Common::strcpy_s(tmpPtr, sizeof("MUND-BEATMUNG!"), "MUND BEATMUNG!");
|
||||
|
||||
// work around bug #1940 (line width exceeded when talking to gardener using spanish text)
|
||||
// This text apparently only is broken in the floppy versions, the CD versions contain
|
||||
// the correct string "MANIFESTACION - ARTISTICA.", which doesn't break the algorithm/game.
|
||||
tmpPtr = strstr(textPtr, "MANIFESTACION-ARTISTICA.");
|
||||
if (tmpPtr)
|
||||
strcpy(tmpPtr, "MANIFESTACION ARTISTICA.");
|
||||
// We are sure there is at least this space and we replace it by something of same length
|
||||
Common::strcpy_s(tmpPtr, sizeof("MANIFESTACION-ARTISTICA."), "MANIFESTACION ARTISTICA.");
|
||||
|
||||
char *curPos = textPtr;
|
||||
char *lastSpace = textPtr;
|
||||
@ -455,7 +457,7 @@ bool Text::patchMessage(uint32 textNum) {
|
||||
uint16 patchNum = _patchLangNum[SkyEngine::_systemVars->language];
|
||||
for (uint16 cnt = 0; cnt < patchNum; cnt++) {
|
||||
if (_patchedMessages[cnt + patchIdx].textNr == textNum) {
|
||||
strcpy(_textBuffer, _patchedMessages[cnt + patchIdx].text);
|
||||
Common::strcpy_s(_textBuffer, _patchedMessages[cnt + patchIdx].text);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user