Skip to content

Conversation

@bobtista
Copy link

Summary

Fixes uninitialized memory bug in LAN game announcement messages when announcing games to the lobby.

TODO

Testing

@bobtista bobtista self-assigned this Nov 11, 2025
strlcpy(reply.GameInfo.options, gameOpts.str(), ARRAY_SIZE(reply.GameInfo.options));
wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameInfo.gameName));
reply.GameInfo.inProgress = m_currentGame->isGameInProgress();
reply.GameInfo.isDirectConnect = m_currentGame->getIsDirectConnect();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What issue did this cause then? Was Direct Connect game visible in Network Lobby when it should not have been?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have my PC to check this, I was just following the notes in the Issue. handleRequestLocations handler wasn't setting reply.GameInfo.isDirectConnect when building the game announcement message, so could we end up sending uninitialized data in that specific message struct? Does LANMessage reply also get auto zeroed?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to test the consequence of this bug so we can properly describe what this change fixes.

//Initializtions missing and needed
m_lastHeard = 0;
m_next = NULL;
m_isDirectConnect = false;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you certain this caused uninitialized memory use on runtime? LANGameInfo is allocated through Game Memory overloads, which means its memory is memset 0 before the constructor is called. So if you look at this object in debugger, then this field should 0 regardless.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think you're right here. Is it still good practice to do it explicitly here? If not, I can just drop that commit.

Copy link

@xezon xezon Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens all over the code base. Class members are not explicitly zero initialized, which is a mistake in principle, but the memory allocator is forgiving (and very pessimistic) by zeroing every allocation.

@Caball009
Copy link

Caball009 commented Nov 12, 2025

In some cases msg->GameInfo.isDirectConnect shows up as uninitialized (0xCC) for me here:

game->setIsDirectConnect(msg->GameInfo.isDirectConnect);

Reproduction:

  1. Debug client 1.
  2. Create a LAN game with client 2.
  3. Join the lobby with client 1.

Maybe it only happens the first time that code executes after joining the lobby.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Always set isDirectConnect variable when announcing LAN game

3 participants