Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(gamenetwork): the size of a null command is no bytes, not one

Olcay Seyganc25f674deb76
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/NetPacket.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/NetPacket.cpp
index 33047ad46..9f2d36a65 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/NetPacket.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/NetPacket.cpp
@@ -249,7 +249,9 @@ UnsignedInt NetPacket::GetBufferSizeNeededForCommand(NetCommandMsg *msg) {
// This is where the fun begins...
if (msg == NULL) {
- return TRUE; // There was nothing to add, so it was successful.
+ // this returns a size, not a success flag - the TRUE it used to hand back reserved one
+ // byte for a command that does not exist
+ return 0;
}
switch(msg->getNetCommandType())
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 4f03fbd3d..9bd4d3170 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -4240,8 +4240,17 @@ struct NetPacketFileReader : public NetPacket
{
using NetPacket::readFileMessage;
using NetPacket::readFileAnnounceMessage;
+ using NetPacket::GetBufferSizeNeededForCommand;
};
+/* The size of nothing is nothing. This one hands back a byte count, but its guard against a null
+ command returned TRUE - so a caller sizing a buffer reserved one byte for a command that is not
+ there. */
+TEST(sizing_a_null_command_asks_for_no_bytes)
+{
+ CHECK_EQ( (Int)NetPacketFileReader::GetBufferSizeNeededForCommand( NULL ), 0 );
+}
+
TEST(an_overlong_transfer_filename_is_truncated_instead_of_overflowing)
{
static const Int NAME_LEN = 400; // _MAX_PATH is 260