LURE: Safer string manipulation

This commit is contained in:
Eugene Sandulenko 2016-05-13 09:23:20 +02:00
parent d8caeed074
commit 8577606b04
3 changed files with 18 additions and 18 deletions

View File

@ -538,7 +538,7 @@ void Game::handleRightClickMenu() {
hotspot = res.getHotspot(room.hotspotId());
assert(hotspot);
strings.getString(hotspot->nameId, statusLine);
strcat(statusLine, stringList.getString(S_FOR));
Common::strlcat(statusLine, stringList.getString(S_FOR), MAX_DESC_SIZE);
statusLine += strlen(statusLine);
itemId = PopupMenu::ShowItems(GET, player->roomNumber());
@ -549,7 +549,7 @@ void Game::handleRightClickMenu() {
hotspot = res.getHotspot(room.hotspotId());
assert(hotspot);
strings.getString(hotspot->nameId, statusLine);
strcat(statusLine, stringList.getString(S_TO));
Common::strlcat(statusLine, stringList.getString(S_TO), MAX_DESC_SIZE);
breakFlag = GetTellActions();
break;
@ -559,7 +559,7 @@ void Game::handleRightClickMenu() {
case DRINK:
hasItems = (res.numInventoryItems() != 0);
if (!hasItems)
strcat(statusLine, stringList.getString(S_ACTION_NOTHING));
Common::strlcat(statusLine, stringList.getString(S_ACTION_NOTHING), MAX_DESC_SIZE);
statusLine += strlen(statusLine);
room.update();
@ -579,9 +579,9 @@ void Game::handleRightClickMenu() {
assert(useHotspot);
strings.getString(useHotspot->nameId, statusLine);
if (action == GIVE)
strcat(statusLine, stringList.getString(S_TO));
Common::strlcat(statusLine, stringList.getString(S_TO), MAX_DESC_SIZE);
else
strcat(statusLine, stringList.getString(S_ON));
Common::strlcat(statusLine, stringList.getString(S_ON), MAX_DESC_SIZE);
statusLine += strlen(statusLine);
}
else if ((action == DRINK) || (action == EXAMINE))

View File

@ -1898,8 +1898,8 @@ void Hotspot::doStatus(HotspotData *hotspot) {
endAction();
strings.getString(room.roomNumber(), buffer);
strcat(buffer, "\n\n");
strcat(buffer, stringList.getString(S_YOU_ARE_CARRYING));
Common::strlcat(buffer, "\n\n", MAX_DESC_SIZE);
Common::strlcat(buffer, stringList.getString(S_YOU_ARE_CARRYING), MAX_DESC_SIZE);
// Scan through the list and add in any items assigned to the player
HotspotDataList &list = res.hotspotData();
@ -1909,25 +1909,25 @@ void Hotspot::doStatus(HotspotData *hotspot) {
if (rec.roomNumber == PLAYER_ID) {
if (numItems++ == 0)
strcat(buffer, ": ");
Common::strlcat(buffer, ": ", MAX_DESC_SIZE);
else
strcat(buffer, ", ");
Common::strlcat(buffer, ", ", MAX_DESC_SIZE);
strings.getString(rec.nameId, buffer + strlen(buffer));
}
}
// If there were no items, add in the word 'nothing'
if (numItems == 0)
strcat(buffer, stringList.getString(S_INV_NOTHING));
Common::strlcat(buffer, stringList.getString(S_INV_NOTHING), MAX_DESC_SIZE);
// If the player has money, add it in
uint16 numGroats = res.fieldList().numGroats();
if (numGroats > 0) {
strcat(buffer, "\n\n");
strcat(buffer, stringList.getString(S_YOU_HAVE));
sprintf(buffer + strlen(buffer), "%d", numGroats);
strcat(buffer, " ");
strcat(buffer, stringList.getString((numGroats == 1) ? S_GROAT : S_GROATS));
Common::strlcat(buffer, "\n\n", MAX_DESC_SIZE);
Common::strlcat(buffer, stringList.getString(S_YOU_HAVE), MAX_DESC_SIZE);
snprintf(buffer + strlen(buffer), MAX_DESC_SIZE, "%d", numGroats);
Common::strlcat(buffer, " ", MAX_DESC_SIZE);
Common::strlcat(buffer, stringList.getString((numGroats == 1) ? S_GROAT : S_GROATS), MAX_DESC_SIZE); // Make sure we're not overrunning
}
// Display the dialog

View File

@ -926,8 +926,8 @@ uint16 Script::execute(uint16 startOffset) {
opcode >>= 1;
if (gDebugLevel >= ERROR_DETAILED)
strcat(debugInfo, (opcode > S_OPCODE_RANDOM) ? "INVALID" :
scriptOpcodes[opcode]);
Common::strlcat(debugInfo, (opcode > S_OPCODE_RANDOM) ? "INVALID" :
scriptOpcodes[opcode], MAX_DESC_SIZE);
if (hasParam) {
// Flag to read next two bytes as active parameter
@ -1087,7 +1087,7 @@ uint16 Script::execute(uint16 startOffset) {
else if (scriptMethodNames[param] == NULL) strcat(debugInfo, " UNKNOWN METHOD");
else {
strcat(debugInfo, " ");
strcat(debugInfo, scriptMethodNames[param]);
Common::strlcat(debugInfo, scriptMethodNames[param], MAX_DESC_SIZE);
}
// Any params