From 42b947d470105ca109e219577817da159c4e5af8 Mon Sep 17 00:00:00 2001 From: "Marco Antonio J. Costa" Date: Wed, 22 Jul 2026 11:54:16 -0300 Subject: [PATCH] give three temporaries a name before taking their address Each of these takes the address of an object that has no name: bool b = client->Startup(1,30,&SocketDescriptor(), 1); OutputToStream(msg, &(SGP_LOG(s_log.id))); MSVC allows it as an extension. The temporary lives to the end of the full expression, which is past the call, so all three happen to work; clang rejects the address-of outright. Naming the object changes nothing about when it is built or what is passed, only that the pointer now refers to something that outlives the statement. MemMan.cpp already does this with the same logger call: sgp::Logger::LogInstance memLeak = SGP_LOG(log_id); Verification: ninja -C build parse # address-of-temporary class gone: 24 -> 21 sites ninja -C build -k 0 # Release, four applications, green ninja -C build-debug -k 0 # Debug, four applications, green Co-Authored-By: Claude Opus 4.8 --- Multiplayer/client.cpp | 3 ++- Multiplayer/server.cpp | 3 ++- sgp/debug_win_util.cpp | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Multiplayer/client.cpp b/Multiplayer/client.cpp index 9570e83b8..c1f1d84ad 100644 --- a/Multiplayer/client.cpp +++ b/Multiplayer/client.cpp @@ -4818,7 +4818,8 @@ void connect_client ( void ) ScreenMsg( FONT_BEIGE, MSG_MPSYSTEM, MPClientMessage[0] ); client = RakNetworkFactory::GetRakPeerInterface(); - bool b = client->Startup(1,30,&SocketDescriptor(), 1); + SocketDescriptor socketDescriptor; + bool b = client->Startup(1,30,&socketDescriptor, 1); //RPC's REGISTER_STATIC_RPC(client, recievePATH); diff --git a/Multiplayer/server.cpp b/Multiplayer/server.cpp index 627165ebd..7e3d3b338 100644 --- a/Multiplayer/server.cpp +++ b/Multiplayer/server.cpp @@ -1025,7 +1025,8 @@ void start_server (void) server->SetTimeoutTime(120000, UNASSIGNED_SYSTEM_ADDRESS); // 120 Seconds - bool b = server->Startup(gMaxClients, 30, &SocketDescriptor(serverPort,0), 1); + SocketDescriptor socketDescriptor(serverPort,0); + bool b = server->Startup(gMaxClients, 30, &socketDescriptor, 1); server->SetMaximumIncomingConnections((gMaxClients)); server->SetOccasionalPing(true); diff --git a/sgp/debug_win_util.cpp b/sgp/debug_win_util.cpp index 6da53bc97..ce1fa5e44 100644 --- a/sgp/debug_win_util.cpp +++ b/sgp/debug_win_util.cpp @@ -204,7 +204,8 @@ static struct StackTraceLog { } s_log; void StackTrace::PrintBacktrace(const char* msg) { - OutputToStream(msg, &(SGP_LOG(s_log.id))); + sgp::Logger::LogInstance log = SGP_LOG(s_log.id); + OutputToStream(msg, &log); } void StackTrace::OutputToStream(const char* msg, sgp::Logger::LogInstance* os) {