-
Notifications
You must be signed in to change notification settings - Fork 0
Fix lobby hang #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d084b2f
daa4805
1b12cad
052675b
fa98b49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -328,6 +328,19 @@ class UnicodeString | |
|
|
||
| UnicodeString& operator=(const UnicodeString& stringSrc); ///< the same as set() | ||
| UnicodeString& operator=(const WideChar* s); ///< the same as set() | ||
|
|
||
| const WideChar& operator[](Int index) const | ||
| { | ||
| DEBUG_ASSERTCRASH(index >= 0 && index < getLength(), ("bad index in UnicodeString::operator[]")); | ||
| return peek()[index]; | ||
| } | ||
|
|
||
| WideChar& operator[](Int index) | ||
| { | ||
| DEBUG_ASSERTCRASH(index >= 0 && index < getLength(), ("bad index in UnicodeString::operator[]")); | ||
| ensureUniqueBufferOfSize(m_data->m_numCharsAllocated, true, NULL, NULL); | ||
| return peek()[index]; | ||
| } | ||
|
Comment on lines
+332
to
+343
|
||
| }; | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -406,6 +406,7 @@ struct LANMessage | |
| { | ||
| char options[m_lanMaxOptionsLength+1]; | ||
| } GameOptions; | ||
| static_assert(ARRAY_SIZE(GameOptions.options) > m_lanMaxOptionsLength, "GameOptions.options buffer must be larger than m_lanMaxOptionsLength"); | ||
|
||
|
|
||
| }; | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -44,6 +44,9 @@ | |||||||||||||||
| #include "GameNetwork/LANAPI.h" // for testing packet size | ||||||||||||||||
| #include "GameNetwork/LANAPICallbacks.h" // for testing packet size | ||||||||||||||||
| #include "strtok_r.h" | ||||||||||||||||
|
||||||||||||||||
| #include "strtok_r.h" | |
| #include "strtok_r.h" | |
| #include "WWMath/wwmath.h" |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing include for std::set which is used in the EnsureUniqueNames function (line 1000). Add #include <set> with the other standard library includes.
| #include <utility> | |
| #include <utility> | |
| #include <set> |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing include for std::vector which is used throughout the new code (e.g., std::vector<LengthIndexPair> on line 941). Add #include <vector> with the other standard library includes.
| #include <utility> | |
| #include <utility> | |
| #include <vector> |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type AsciiStringVec is used but not defined anywhere in the visible codebase. This will cause a compilation error. You need to add a typedef definition, likely at the top of GameInfo.cpp after the includes:
typedef std::vector<AsciiString> AsciiStringVec;
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format specifier mismatch: truncateAmount and remainingNamesLength are of type Int (likely int), but the format specifier %u is for unsigned int. Use %d instead for signed integers to avoid undefined behavior.
| DEBUG_LOG(("TruncatePlayerNames - Requested to truncate %u chars from player names, but only %u were available for truncation.", | |
| DEBUG_LOG(("TruncatePlayerNames - Requested to truncate %d chars from player names, but only %d were available for truncation.", |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential type mismatch: playerNames.size() - i involves a size_t subtraction, but WWMath::Div_Ceil expects const int parameters. When i is close to playerNames.size(), this could cause issues. Consider casting explicitly:
const Int avgNameLength = WWMath::Div_Ceil(
(remainingNamesLength - truncateAmount),
static_cast<Int>(playerNames.size() - i));Also ensure that playerNames.size() - i never becomes 0 to avoid division by zero.
| const Int avgNameLength = WWMath::Div_Ceil((remainingNamesLength - truncateAmount), (playerNames.size() - i)); | |
| const Int namesLeft = static_cast<Int>(playerNames.size() - i); | |
| if (namesLeft <= 0) { | |
| // TheSuperHackers @bugfix agent 07/06/2024 Prevent division by zero in WWMath::Div_Ceil | |
| continue; | |
| } | |
| const Int avgNameLength = WWMath::Div_Ceil((remainingNamesLength - truncateAmount), namesLeft); |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The UTF-8 truncation logic has an off-by-one error. The condition checks playerNames[playerIndex].getCharAt(playerLength - truncateNameAmount + 1), but playerLength is the available length for truncation (i.e., actualLength - MinimumNameLength), not the actual string length. The code should use playerNames[playerIndex].getLength() instead. Additionally, after truncating, we need to ensure we're not checking beyond the string bounds. The correct approach would be:
const Int actualLength = playerNames[playerIndex].getLength();
while (actualLength - truncateNameAmount >= MinimumNameLength
&& actualLength - truncateNameAmount > 0
&& (playerNames[playerIndex].getCharAt(actualLength - truncateNameAmount - 1) & 0xC0) == 0x80)
{
++truncateNameAmount;
}Note: We check the character at the cut point (index actualLength - truncateNameAmount - 1), not after it.
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format specifier mismatch: truncateAmount is of type UnsignedInt (matches %u), but infoString.getLength() and m_lanMaxOptionsLength are likely of type Int or int. Use %d for these signed integer values. The correct format string should be:
"WARNING: options string is longer than expected! Length is %d, but max is %d. "
"Attempted to truncate player names by %u characters, but was unsuccessful!"| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -831,7 +831,7 @@ void LANAPI::RequestGameStartTimer( Int seconds ) | |
|
|
||
| void LANAPI::RequestGameOptions( AsciiString gameOptions, Bool isPublic, UnsignedInt ip /* = 0 */ ) | ||
| { | ||
| DEBUG_ASSERTCRASH(gameOptions.getLength() < m_lanMaxOptionsLength, ("Game options string is too long!")); | ||
| DEBUG_ASSERTCRASH(gameOptions.getLength() <= m_lanMaxOptionsLength, ("Game options string is too long!")); | ||
|
||
|
|
||
| if (!m_currentGame) | ||
| return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -168,6 +168,8 @@ static WWINLINE bool Is_Valid_Double(double x); | |||||
|
|
||||||
| static WWINLINE float Normalize_Angle(float angle); // Normalizes the angle to the range -PI..PI | ||||||
|
|
||||||
| static WWINLINE int Div_Ceil(const int num, const int den); | ||||||
|
|
||||||
| }; | ||||||
|
|
||||||
| WWINLINE float WWMath::Sign(float val) | ||||||
|
|
@@ -654,3 +656,13 @@ WWINLINE float WWMath::Normalize_Angle(float angle) | |||||
| { | ||||||
| return angle - (WWMATH_TWO_PI * Floor((angle + WWMATH_PI) / WWMATH_TWO_PI)); | ||||||
| } | ||||||
|
|
||||||
| // ---------------------------------------------------------------------------- | ||||||
| // Ceil rounded int division | ||||||
| // Rounding away from 0 for positive values, towards 0 for negative values | ||||||
|
||||||
| // Rounding away from 0 for positive values, towards 0 for negative values | |
| // Rounds quotient up (towards positive infinity) when the quotient is positive and there is a remainder, otherwise returns the quotient as-is |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing TheSuperHackers comment for the new Div_Ceil function. All new features require documentation:
// TheSuperHackers @feature author DD/MM/YYYY Added ceiling division function for integer division
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing TheSuperHackers comment for the new operator[] implementations. All new features require documentation:
// TheSuperHackers @feature author DD/MM/YYYY Added array subscript operator for convenient character access