Skip to content

Commit 28a7e0b

Browse files
author
Bart Roossien
committed
Revert unicodeString changes and convert to ARRAY_SIZE
1 parent e1373c9 commit 28a7e0b

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

Core/GameEngine/Source/Common/System/UnicodeString.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ void UnicodeString::ensureUniqueBufferOfSize(int numCharsNeeded, Bool preserveDa
116116
if (strToCopy)
117117
{
118118
DEBUG_ASSERTCRASH(usableNumChars <= wcslen(strToCopy), ("strToCopy is too small"));
119-
wcslcpy(newData->peek(), strToCopy, usableNumChars + 1);
119+
wcsncpy(newData->peek(), strToCopy, usableNumChars);
120+
newData->peek()[usableNumChars] = 0;
120121
}
121122
if (strToCat)
122123
wcscat(newData->peek(), strToCat);

GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ void LANAPI::update( void )
519519
LANMessage msg;
520520
fillInLANMessage( &msg );
521521
msg.LANMessageType = LANMessage::MSG_REQUEST_GAME_LEAVE;
522-
wcslcpy(msg.name, m_currentGame->getPlayerName(0).str(), g_lanPlayerNameLength + 1);
522+
wcslcpy(msg.name, m_currentGame->getPlayerName(0).str(), ARRAY_SIZE(msg.name));
523523
handleRequestGameLeave(&msg, m_currentGame->getIP(0));
524524
UnicodeString text;
525525
text = TheGameText->fetch("LAN:HostNotResponding");
@@ -537,7 +537,7 @@ void LANAPI::update( void )
537537
UnicodeString theStr;
538538
theStr.format(TheGameText->fetch("LAN:PlayerDropped"), m_currentGame->getPlayerName(p).str());
539539
msg.LANMessageType = LANMessage::MSG_REQUEST_GAME_LEAVE;
540-
wcslcpy(msg.name, m_currentGame->getPlayerName(p).str(), g_lanPlayerNameLength + 1);
540+
wcslcpy(msg.name, m_currentGame->getPlayerName(p).str(), ARRAY_SIZE(msg.name));
541541
handleRequestGameLeave(&msg, m_currentGame->getIP(p));
542542
OnChat(UnicodeString::TheEmptyString, m_localIP, theStr, LANCHAT_SYSTEM);
543543
}
@@ -668,7 +668,7 @@ void LANAPI::RequestGameJoinDirectConnect(UnsignedInt ipaddress)
668668
msg.LANMessageType = LANMessage::MSG_REQUEST_GAME_INFO;
669669
fillInLANMessage(&msg);
670670
msg.PlayerInfo.ip = GetLocalIP();
671-
wcslcpy(msg.PlayerInfo.playerName, m_name.str(), m_name.getLength() + 1);
671+
wcslcpy(msg.PlayerInfo.playerName, m_name.str(), ARRAY_SIZE(msg.PlayerInfo.playerName));
672672

673673
sendMessage(&msg, ipaddress);
674674

@@ -681,7 +681,7 @@ void LANAPI::RequestGameLeave( void )
681681
LANMessage msg;
682682
msg.LANMessageType = LANMessage::MSG_REQUEST_GAME_LEAVE;
683683
fillInLANMessage( &msg );
684-
wcslcpy(msg.GameToLeave.gameName, (m_currentGame)?m_currentGame->getName().str():L"", g_lanGameNameLength + 1);
684+
wcslcpy(msg.GameToLeave.gameName, (m_currentGame)?m_currentGame->getName().str():L"", ARRAY_SIZE(msg.GameToLeave.gameName));
685685
sendMessage(&msg);
686686
m_transport->update(); // Send immediately, before OnPlayerLeave below resets everything.
687687

@@ -713,7 +713,7 @@ void LANAPI::RequestGameAnnounce( void )
713713

714714
AsciiString gameOpts = GameInfoToAsciiString(m_currentGame);
715715
strlcpy(reply.GameInfo.options,gameOpts.str(), ARRAY_SIZE(reply.GameOptions.options));
716-
wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength + 1);
716+
wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameInfo.gameName));
717717
reply.GameInfo.inProgress = m_currentGame->isGameInProgress();
718718
reply.GameInfo.isDirectConnect = m_currentGame->getIsDirectConnect();
719719

@@ -731,7 +731,7 @@ void LANAPI::RequestAccept( void )
731731
fillInLANMessage( &msg );
732732
msg.LANMessageType = LANMessage::MSG_SET_ACCEPT;
733733
msg.Accept.isAccepted = true;
734-
wcslcpy(msg.Accept.gameName, m_currentGame->getName().str(), g_lanGameNameLength + 1);
734+
wcslcpy(msg.Accept.gameName, m_currentGame->getName().str(), ARRAY_SIZE(msg.Accept.gameName));
735735
sendMessage(&msg);
736736
}
737737

@@ -744,7 +744,7 @@ void LANAPI::RequestHasMap( void )
744744
fillInLANMessage( &msg );
745745
msg.LANMessageType = LANMessage::MSG_MAP_AVAILABILITY;
746746
msg.MapStatus.hasMap = m_currentGame->getSlot(m_currentGame->getLocalSlotNum())->hasMap();
747-
wcslcpy(msg.MapStatus.gameName, m_currentGame->getName().str(), g_lanGameNameLength + 1);
747+
wcslcpy(msg.MapStatus.gameName, m_currentGame->getName().str(), ARRAY_SIZE(msg.MapStatus.gameName));
748748
CRC mapNameCRC;
749749
//mapNameCRC.computeCRC(m_currentGame->getMap().str(), m_currentGame->getMap().getLength());
750750
AsciiString portableMapName = TheGameState->realMapPathToPortableMapPath(m_currentGame->getMap());
@@ -781,10 +781,10 @@ void LANAPI::RequestChat( UnicodeString message, ChatType format )
781781
{
782782
LANMessage msg;
783783
fillInLANMessage( &msg );
784-
wcslcpy(msg.Chat.gameName, (m_currentGame)?m_currentGame->getName().str():L"", g_lanGameNameLength + 1);
784+
wcslcpy(msg.Chat.gameName, (m_currentGame)?m_currentGame->getName().str():L"", ARRAY_SIZE(msg.Chat.gameName));
785785
msg.LANMessageType = LANMessage::MSG_CHAT;
786786
msg.Chat.chatType = format;
787-
wcslcpy(msg.Chat.message, message.str(), g_lanMaxChatLength + 1);
787+
wcslcpy(msg.Chat.message, message.str(), ARRAY_SIZE(msg.Chat.message));
788788
sendMessage(&msg);
789789

790790
OnChat(m_name, m_localIP, message, format);
@@ -933,7 +933,7 @@ void LANAPI::RequestGameCreate( UnicodeString gameName, Bool isDirectConnect )
933933
//RequestSlotList();
934934
/*
935935
LANMessage msg;
936-
wcslcpy(msg.name, m_name.str(), g_lanPlayerNameLength + 1);
936+
wcslcpy(msg.name, m_name.str(), ARRAY_SIZE(msg.name));
937937
wcscpy(msg.GameInfo.gameName, myGame->getName().str());
938938
for (player=0; player<MAX_SLOTS; ++player)
939939
{
@@ -1004,15 +1004,15 @@ void LANAPI::RequestSlotList( void )
10041004
10051005
LANMessage reply;
10061006
reply.LANMessageType = LANMessage::MSG_GAME_ANNOUNCE;
1007-
wcslcpy(reply.name, m_name.str(), g_lanPlayerNameLength + 1);
1007+
wcslcpy(reply.name, m_name.str(), ARRAY_SIZE(reply.name));
10081008
int player;
10091009
for (player = 0; player < MAX_SLOTS; ++player)
10101010
{
1011-
wcslcpy(reply.GameInfo.name[player], m_currentGame->getPlayerName(player).str(), g_lanPlayerNameLength + 1);
1011+
wcslcpy(reply.GameInfo.name[player], m_currentGame->getPlayerName(player).str(), ARRAY_SIZE(reply.GameInfo.name[player]));
10121012
reply.GameInfo.ip[player] = m_currentGame->getIP(player);
10131013
reply.GameInfo.playerAccepted[player] = m_currentGame->getSlot(player)->isAccepted();
10141014
}
1015-
wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength + 1);
1015+
wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameInfo.gameName));
10161016
reply.GameInfo.inProgress = m_currentGame->isGameInProgress();
10171017
10181018
sendMessage(&reply);
@@ -1068,7 +1068,7 @@ void LANAPI::fillInLANMessage( LANMessage *msg )
10681068
if (!msg)
10691069
return;
10701070

1071-
wcslcpy(msg->name, m_name.str(), g_lanPlayerNameLength + 1);
1071+
wcslcpy(msg->name, m_name.str(), ARRAY_SIZE(msg->name));
10721072
strlcpy(msg->userName, m_userName.str(), ARRAY_SIZE(msg->userName));
10731073
strlcpy(msg->hostName, m_hostName.str(), ARRAY_SIZE(msg->hostName));
10741074
}

GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void LANAPI::handleRequestLocations( LANMessage *msg, UnsignedInt senderIP )
6363
reply.LANMessageType = LANMessage::MSG_GAME_ANNOUNCE;
6464
AsciiString gameOpts = GenerateGameOptionsString();
6565
strlcpy(reply.GameInfo.options,gameOpts.str(), ARRAY_SIZE(reply.GameInfo.options));
66-
wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength + 1);
66+
wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameInfo.gameName));
6767
reply.GameInfo.inProgress = m_currentGame->isGameInProgress();
6868

6969
sendMessage(&reply);
@@ -193,7 +193,7 @@ void LANAPI::handleRequestGameInfo( LANMessage *msg, UnsignedInt senderIP )
193193

194194
AsciiString gameOpts = GameInfoToAsciiString(m_currentGame);
195195
strlcpy(reply.GameInfo.options,gameOpts.str(), ARRAY_SIZE(reply.GameInfo.options));
196-
wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength + 1);
196+
wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameInfo.gameName));
197197
reply.GameInfo.inProgress = m_currentGame->isGameInProgress();
198198
reply.GameInfo.isDirectConnect = m_currentGame->getIsDirectConnect();
199199

@@ -313,7 +313,7 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP )
313313
{
314314
// OK, add him in.
315315
reply.LANMessageType = LANMessage::MSG_JOIN_ACCEPT;
316-
wcslcpy(reply.GameJoined.gameName, m_currentGame->getName().str(), g_lanGameNameLength + 1);
316+
wcslcpy(reply.GameJoined.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameJoined.gameName));
317317
reply.GameJoined.slotPosition = player;
318318
reply.GameJoined.gameIP = m_localIP;
319319
reply.GameJoined.playerIP = senderIP;
@@ -337,7 +337,7 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP )
337337
if (canJoin && player == MAX_SLOTS)
338338
{
339339
reply.LANMessageType = LANMessage::MSG_JOIN_DENY;
340-
wcslcpy(reply.GameNotJoined.gameName, m_currentGame->getName().str(), g_lanGameNameLength + 1);
340+
wcslcpy(reply.GameNotJoined.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameNotJoined.gameName));
341341
reply.GameNotJoined.reason = LANAPIInterface::RET_GAME_FULL;
342342
reply.GameNotJoined.gameIP = m_localIP;
343343
reply.GameNotJoined.playerIP = senderIP;

0 commit comments

Comments
 (0)