CINE: Don't use unsafe strcat and strcpy

This commit is contained in:
Le Philousophe 2022-09-24 12:30:57 +02:00 committed by Eugene Sandulenko
parent e871394664
commit c618b7fe91
9 changed files with 43 additions and 43 deletions

View File

@ -243,7 +243,7 @@ AnimData::AnimData(const AnimData &src) : _width(src._width),
}
memset(_name, 0, sizeof(_name));
strcpy(_name, src._name);
Common::strcpy_s(_name, src._name);
}
/**
@ -276,7 +276,7 @@ AnimData &AnimData::operator=(const AnimData &src) {
_fileIdx = tmp._fileIdx;
_frameIdx = tmp._frameIdx;
memset(_name, 0, sizeof(_name));
strcpy(_name, tmp._name);
Common::strcpy_s(_name, tmp._name);
_realWidth = tmp._realWidth;
_size = tmp._size;
@ -458,7 +458,7 @@ void freeAnimDataTable() {
static byte getAnimTransparentColor(const char *animName) {
char name[15];
removeExtention(name, animName);
removeExtention(name, animName, sizeof(name));
for (int i = 0; i < ARRAYSIZE(transparencyData); i++) {
if (!strcmp(name, transparencyData[i].name)) {
@ -867,7 +867,7 @@ int loadResource(const char *resourceName, int16 idx, int16 frameIndex) {
g_sound->musicType() != MT_MT32 &&
(strstr(resourceName, ".SPL") || strstr(resourceName, ".H32"))) {
char base[20];
removeExtention(base, resourceName);
removeExtention(base, resourceName, sizeof(base));
for (uint i = 0; i < ARRAYSIZE(resNameMapping); i++) {
if (scumm_stricmp(base, resNameMapping[i].from) == 0) {

View File

@ -263,7 +263,7 @@ void CineEngine::initialize() {
if (getGameType() == Cine::GType_OS && !(getFeatures() & GF_DEMO) &&
(getPlatform() == Common::kPlatformDOS || getPlatform() == Common::kPlatformAtariST)) {
loadPrc(BOOT_PRC_NAME);
strcpy(currentPrcName, BOOT_PRC_NAME);
Common::strcpy_s(currentPrcName, BOOT_PRC_NAME);
addScriptToGlobalScripts(BOOT_SCRIPT_INDEX);
runOnlyUntilFreePartRangeFirst200 = true;
executeGlobalScripts();
@ -279,7 +279,7 @@ void CineEngine::initialize() {
if (!_preLoad) {
loadPrc(BOOT_PRC_NAME);
strcpy(currentPrcName, BOOT_PRC_NAME);
Common::strcpy_s(currentPrcName, BOOT_PRC_NAME);
setMouseCursor(MOUSE_CURSOR_NORMAL);
}
}

View File

@ -454,12 +454,12 @@ void CineEngine::mainLoop(int bootScriptIdx) {
renderer->setBlackPalette(true); // Sets _changePal = true
strcpy(newPrcName, "");
strcpy(newRelName, "");
strcpy(newObjectName, "");
strcpy(newMsgName, "");
strcpy(currentCtName, "");
strcpy(currentPartName, "");
newPrcName[0] = '\0';
newRelName[0] = '\0';
newObjectName[0] = '\0';
newMsgName[0] = '\0';
currentCtName[0] = '\0';
currentPartName[0] = '\0';
g_sound->stopMusic();
}

View File

@ -35,9 +35,9 @@ static byte paletteBuffer2[16];
void loadPal(const char *fileName) {
char buffer[20];
removeExtention(buffer, fileName);
removeExtention(buffer, fileName, sizeof(buffer));
strcat(buffer, ".PAL");
Common::strcat_s(buffer, ".PAL");
g_cine->_palArray.clear();
Common::File palFileHandle;
@ -86,7 +86,7 @@ void loadRelatedPalette(const char *fileName) {
byte i;
int16 paletteIndex;
removeExtention(localName, fileName);
removeExtention(localName, fileName, sizeof(localName));
paletteIndex = findPaletteFromName(localName);

View File

@ -289,7 +289,7 @@ byte *readBundleSoundFileFW(const char *entryName, uint32 *size) {
char previousPartName[15] = "";
if (g_cine->getGameType() == Cine::GType_FW) {
strcpy(previousPartName, currentPartName);
Common::strcpy_s(previousPartName, currentPartName);
loadPart("BASESON.SND");
}
index = findFileInBundle((const char *)entryName);
@ -354,7 +354,7 @@ void checkDataDisk(int16 diskNum) {
void dumpBundle(const char *fileName) {
char tmpPart[15];
strcpy(tmpPart, currentPartName);
Common::strcpy_s(tmpPart, currentPartName);
loadPart(fileName);
for (uint i = 0; i < g_cine->_partBuffer.size(); i++) {

View File

@ -710,7 +710,7 @@ bool CineEngine::loadPlainSaveFW(Common::SeekableReadStream &in, CineSaveGameFor
if (strlen(bgName)) {
if (g_cine->getGameType() == GType_FW && (g_cine->getFeatures() & GF_CD)) {
char buffer[20];
removeExtention(buffer, bgName);
removeExtention(buffer, bgName, sizeof(buffer));
g_sound->setBgMusic(atoi(buffer + 1));
}
loadBg(bgName);
@ -1049,7 +1049,7 @@ void loadResourcesFromSave(Common::SeekableReadStream &fHandle, enum CineSaveGam
int16 foundFileIdx;
char *animName, part[256], name[10];
strcpy(part, currentPartName);
Common::strcpy_s(part, currentPartName);
// We only support these variations of the savegame format at the moment.
assert(saveGameFormat == ANIMSIZE_23 || saveGameFormat == ANIMSIZE_30_PTRS_INTACT);

View File

@ -1380,7 +1380,7 @@ int FWScript::o1_loadBg() {
if (g_cine->getGameType() == GType_FW && (g_cine->getFeatures() & GF_CD)) {
char buffer[20];
removeExtention(buffer, param);
removeExtention(buffer, param, sizeof(buffer));
g_sound->setBgMusic(atoi(buffer + 1));
}
@ -2212,7 +2212,7 @@ void decompileScript(const byte *scriptPtr, uint16 scriptSize, uint16 scriptIdx)
opcode = 0;
}
strcpy(lineBuffer, "");
Common::strcpy_s(lineBuffer, "");
switch (opcode - 1) {
case -1: {
@ -3222,7 +3222,7 @@ void decompileScript(const byte *scriptPtr, uint16 scriptSize, uint16 scriptIdx)
}
//printf(lineBuffer);
strcpy(decompileBuffer[decompileBufferPosition++], lineBuffer);
Common::strcpy_s(decompileBuffer[decompileBufferPosition++], lineBuffer);
exitScript = 0;
if (position >= scriptSize) {

View File

@ -312,11 +312,11 @@ void CineEngine::resetEngine() {
bgVar0 = 0;
var2 = var3 = var4 = lastType20OverlayBgIdx = 0;
strcpy(newPrcName, "");
strcpy(newRelName, "");
strcpy(newObjectName, "");
strcpy(newMsgName, "");
strcpy(currentCtName, "");
newPrcName[0] = '\0';
newRelName[0] = '\0';
newObjectName[0] = '\0';
newMsgName[0] = '\0';
currentCtName[0] = '\0';
allowPlayerInput = 0;
waitForPlayerClick = 0;
@ -609,7 +609,7 @@ int16 buildObjectListCommand(int16 param) {
for (i = 0; i < 255; i++) {
if (g_cine->_objectTable[i].name[0] && g_cine->_objectTable[i].costume == param) {
strcpy(objectListCommand[j], g_cine->_objectTable[i].name);
Common::strcpy_s(objectListCommand[j], g_cine->_objectTable[i].name);
objListTab[j] = i;
j++;
}
@ -1471,8 +1471,8 @@ void checkForPendingDataLoad() {
if (newPrcName[0] != 0) {
bool loadPrcOk = loadPrc(newPrcName);
strcpy(currentPrcName, newPrcName);
strcpy(newPrcName, "");
Common::strcpy_s(currentPrcName, newPrcName);
newPrcName[0] = '\0';
// Check that the loading of the script file was successful before
// trying to add script 1 from it to the global scripts list. This
@ -1490,8 +1490,8 @@ void checkForPendingDataLoad() {
if (newRelName[0] != 0) {
loadRel(newRelName);
strcpy(currentRelName, newRelName);
strcpy(newRelName, "");
Common::strcpy_s(currentRelName, newRelName);
newRelName[0] = '\0';
}
if (newObjectName[0] != 0) {
@ -1499,23 +1499,23 @@ void checkForPendingDataLoad() {
loadObject(newObjectName);
strcpy(currentObjectName, newObjectName);
strcpy(newObjectName, "");
Common::strcpy_s(currentObjectName, newObjectName);
newObjectName[0] = '\0';
}
if (newMsgName[0] != 0) {
loadMsg(newMsgName);
strcpy(currentMsgName, newMsgName);
strcpy(newMsgName, "");
Common::strcpy_s(currentMsgName, newMsgName);
newMsgName[0] = '\0';
}
}
void hideMouse() {
}
void removeExtention(char *dest, const char *source) {
strcpy(dest, source);
void removeExtention(char *dest, const char *source, size_t sz) {
Common::strcpy_s(dest, sz, source);
byte *ptr = (byte *) strchr(dest, '.');
@ -1954,7 +1954,7 @@ bool makeTextEntryMenu(const char *messagePtr, char *inputString, int stringMaxL
if (inputPos != inputLength) {
strncat(tempString, &inputString[inputPos], inputLength - inputPos);
}
strcpy(inputString, tempString);
Common::strcpy_s(inputString, stringMaxLength, tempString);
inputLength = strlen(inputString);
redraw = true;
}
@ -1980,16 +1980,16 @@ bool makeTextEntryMenu(const char *messagePtr, char *inputString, int stringMaxL
ch[0] = ascii;
if (inputPos != 1) {
strncpy(tempString, inputString, inputPos - 1);
strcat(tempString, ch);
Common::strcat_s(tempString, ch);
}
if ((inputLength == 0) || (inputPos == 1)) {
strcpy(tempString, ch);
Common::strcpy_s(tempString, ch);
}
if ((inputLength != 0) && (inputPos != inputLength)) {
strncat(tempString, &inputString[inputPos - 1], inputLength - inputPos + 1);
}
strcpy(inputString, tempString);
Common::strcpy_s(inputString, stringMaxLength, tempString);
inputLength = strlen(inputString);
inputPos++;
redraw = true;

View File

@ -133,7 +133,7 @@ void checkForPendingDataLoad();
void hideMouse();
void removeExtention(char *dest, const char *source);
void removeExtention(char *dest, const char *source, size_t sz);
struct SelectedObjStruct {
int16 idx;