Skip to content

Commit

Permalink
Use memset less
Browse files Browse the repository at this point in the history
  • Loading branch information
slipher committed Jun 11, 2024
1 parent 7853307 commit 6959367
Show file tree
Hide file tree
Showing 36 changed files with 68 additions and 96 deletions.
4 changes: 2 additions & 2 deletions src/common/cm/cm_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ static void CM_SurfaceCollideFromGrid( cGrid_t *grid, cSurfaceCollide_t *sc )
}

facet = &facets[ numFacets ];
memset( facet, 0, sizeof( *facet ) );
*facet = {};

if ( gridPlanes[ i ][ j ][ 0 ] == gridPlanes[ i ][ j ][ 1 ] )
{
Expand Down Expand Up @@ -724,7 +724,7 @@ static void CM_SurfaceCollideFromGrid( cGrid_t *grid, cSurfaceCollide_t *sc )
}

facet = &facets[ numFacets ];
memset( facet, 0, sizeof( *facet ) );
*facet = {};

facet->surfacePlane = gridPlanes[ i ][ j ][ 1 ];
facet->numBorders = 3;
Expand Down
3 changes: 1 addition & 2 deletions src/common/cm/cm_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,6 @@ static void CM_Trace( trace_t *results, const vec3_t start, const vec3_t end, co
int skipmask, traceType_t type, const sphere_t *sphere )
{
int i;
traceWork_t tw;
vec3_t offset;
cmodel_t *cmod;

Expand All @@ -1857,7 +1856,7 @@ static void CM_Trace( trace_t *results, const vec3_t start, const vec3_t end, co
c_traces++; // for statistics, may be zeroed

// fill in a default trace
memset( &tw, 0, sizeof( tw ) );
traceWork_t tw{};
tw.trace.fraction = 1; // assume it goes the entire distance until shown otherwise
VectorCopy( origin, tw.modelOrigin );
tw.type = type;
Expand Down
2 changes: 1 addition & 1 deletion src/common/cm/cm_trisoup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static void CM_SurfaceCollideFromTriangleSoup( cTriangleSoup_t *triSoup, cSurfac
for ( i = 0; i < triSoup->numTriangles; i++ )
{
facet = &facets[ numFacets ];
memset( facet, 0, sizeof( *facet ) );
*facet = {};

p1 = triSoup->points[ i ][ 0 ];
p2 = triSoup->points[ i ][ 1 ];
Expand Down
2 changes: 1 addition & 1 deletion src/engine/client/cl_avi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ bool CL_OpenAVIForWriting( const char *fileName )
return false;
}

memset( &afd, 0, sizeof( aviFileData_t ) );
afd = {};

// Don't start if a framerate has not been chosen
if ( cl_aviFrameRate->integer <= 0 )
Expand Down
6 changes: 2 additions & 4 deletions src/engine/client/cl_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,15 +696,14 @@ CL_CreateCmd
*/
usercmd_t CL_CreateCmd()
{
usercmd_t cmd;
vec3_t oldAngles;

VectorCopy( cl.viewangles, oldAngles );

// keyboard angle adjustment
CL_AdjustAngles();

memset( &cmd, 0, sizeof( cmd ) );
usercmd_t cmd{};

CL_CmdButtons( &cmd );

Expand Down Expand Up @@ -872,7 +871,6 @@ void CL_WritePacket()
byte data[ MAX_MSGLEN ];
int j;
usercmd_t *cmd, *oldcmd;
usercmd_t nullcmd;
int packetNum;
int oldPacketNum;
int count;
Expand All @@ -883,7 +881,7 @@ void CL_WritePacket()
return;
}

memset( &nullcmd, 0, sizeof( nullcmd ) );
usercmd_t nullcmd{};
oldcmd = &nullcmd;

MSG_Init( &buf, data, sizeof( data ) );
Expand Down
5 changes: 2 additions & 3 deletions src/engine/client/cl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,7 @@ void CL_Record(std::string demo_name)
}

// baselines
entityState_t nullstate;
memset( &nullstate, 0, sizeof( nullstate ) );
entityState_t nullstate{};

for ( int i = 0; i < MAX_GENTITIES; i++ )
{
Expand Down Expand Up @@ -2292,7 +2291,7 @@ void CL_ShutdownRef()
}

re.Shutdown( true );
memset( &re, 0, sizeof( re ) );
re = {};
}

//===========================================================================================
Expand Down
3 changes: 1 addition & 2 deletions src/engine/client/cl_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ void CL_ParseGamestate( msg_t *msg )
int i;
entityState_t *es;
int newnum;
entityState_t nullstate;
int cmd;

Con_Close();
Expand Down Expand Up @@ -441,7 +440,7 @@ void CL_ParseGamestate( msg_t *msg )
Sys::Drop( "Baseline number out of range: %i", newnum );
}

memset( &nullstate, 0, sizeof( nullstate ) );
entityState_t nullstate{};
es = &cl.entityBaselines[ newnum ];
MSG_ReadDeltaEntity( msg, &nullstate, es, newnum );
}
Expand Down
8 changes: 3 additions & 5 deletions src/engine/client/cl_serverlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,6 @@ void CL_LocalServers_f()
{
const char *message;
int i, j;
netadr_t to;

serverInfoLog.Verbose( "Scanning for servers on the local network…" );

Expand All @@ -688,11 +687,11 @@ void CL_LocalServers_f()
for ( i = 0; i < MAX_OTHER_SERVERS; i++ )
{
bool b = cls.localServers[ i ].visible;
memset( &cls.localServers[ i ], 0, sizeof( cls.localServers[ i ] ) );
cls.localServers[ i ] = {};
cls.localServers[ i ].visible = b;
}

memset( &to, 0, sizeof( to ) );
netadr_t to{};

// The 'xxx' in the message is a challenge that will be echoed back
// by the server. We don't care about that here, but master servers
Expand Down Expand Up @@ -954,7 +953,6 @@ CL_Ping_f
*/
void CL_Ping_f()
{
netadr_t to;
ping_t *pingptr;
const char *server;
int argc;
Expand Down Expand Up @@ -990,7 +988,7 @@ void CL_Ping_f()
server = Cmd_Argv( 2 );
}

memset( &to, 0, sizeof( netadr_t ) );
netadr_t to{};

if ( !NET_StringToAdr( server, &to, family ) )
{
Expand Down
4 changes: 2 additions & 2 deletions src/engine/client/cl_serverstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ CL_ServerStatus_f
*/
void CL_ServerStatus_f()
{
netadr_t to, *toptr = nullptr;
netadr_t *toptr = nullptr;
const char *server;
serverStatus_t *serverStatus;
int argc;
Expand All @@ -307,7 +307,7 @@ void CL_ServerStatus_f()

if ( !toptr )
{
memset( &to, 0, sizeof( netadr_t ) );
netadr_t to{};

if ( argc == 2 )
{
Expand Down
6 changes: 2 additions & 4 deletions src/engine/framework/Rcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ Message::Message( const netadr_t& remote, std::string command,
{}

Message::Message( std::string error_message )
: secure(Secure::Invalid), error(std::move(error_message))
{
memset(&remote, 0, sizeof(remote));
}
: secure(Secure::Invalid), remote{}, error(std::move(error_message))
{}


bool Message::Valid(std::string *invalid_reason) const
Expand Down
6 changes: 2 additions & 4 deletions src/engine/framework/VirtualMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,13 @@ static std::pair<Sys::OSHandle, IPC::Socket> InternalLoadModule(std::pair<IPC::S
HANDLE job = CreateJobObject(nullptr, nullptr);
if (!job)
Sys::Drop("VM: Could not create job object: %s", Sys::Win32StrError(GetLastError()));
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli;
memset(&jeli, 0, sizeof(jeli));
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli{};
jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
if (!SetInformationJobObject(job, JobObjectExtendedLimitInformation, &jeli, sizeof(jeli)))
Sys::Drop("VM: Could not set job object information: %s", Sys::Win32StrError(GetLastError()));

STARTUPINFOW startupInfo;
STARTUPINFOW startupInfo{};
PROCESS_INFORMATION processInfo;
memset(&startupInfo, 0, sizeof(startupInfo));
if (stderrRedirect) {
startupInfo.hStdError = stderrRedirectHandle;
startupInfo.dwFlags = STARTF_USESTDHANDLES;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/null/null_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ refexport_t *GetRefAPI( int, refimport_t* )
{
static refexport_t re;

memset( &re, 0, sizeof( re ) );
re = {};

re.Shutdown = RE_Shutdown;

Expand Down
10 changes: 4 additions & 6 deletions src/engine/qcommon/huffman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ void Huff_Decompress( msg_t *mbuf, int offset )
int ch, cch, i, j, size;
byte seq[ 65536 ];
byte *buffer;
huff_t huff;

size = mbuf->cursize - offset;
buffer = mbuf->data + offset;
Expand All @@ -488,7 +487,7 @@ void Huff_Decompress( msg_t *mbuf, int offset )
return;
}

memset( &huff, 0, sizeof( huff_t ) );
huff_t huff{};
// Initialize the tree & list with the NYT node
huff.tree = huff.lhead = huff.ltail = huff.loc[ NYT ] = & ( huff.nodeList[ huff.blocNode++ ] );
huff.tree->symbol = NYT;
Expand Down Expand Up @@ -545,7 +544,6 @@ void Huff_Compress( msg_t *mbuf, int offset )
int i, ch, size;
byte seq[ 65536 ];
byte *buffer;
huff_t huff;

size = mbuf->cursize - offset;
buffer = mbuf->data + +offset;
Expand All @@ -555,7 +553,7 @@ void Huff_Compress( msg_t *mbuf, int offset )
return;
}

memset( &huff, 0, sizeof( huff_t ) );
huff_t huff{};
// Add the NYT (not yet transmitted) node into the tree/list */
huff.tree = huff.lhead = huff.loc[ NYT ] = & ( huff.nodeList[ huff.blocNode++ ] );
huff.tree->symbol = NYT;
Expand Down Expand Up @@ -584,8 +582,8 @@ void Huff_Compress( msg_t *mbuf, int offset )

void Huff_Init( huffman_t *huff )
{
memset( &huff->compressor, 0, sizeof( huff_t ) );
memset( &huff->decompressor, 0, sizeof( huff_t ) );
ResetStruct( huff->compressor );
ResetStruct( huff->decompressor );

// Initialize the tree & list with the NYT node
huff->decompressor.tree = huff->decompressor.lhead = huff->decompressor.ltail = huff->decompressor.loc[ NYT ] =
Expand Down
6 changes: 3 additions & 3 deletions src/engine/qcommon/msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void MSG_Init( msg_t *buf, byte *data, int length )
MSG_initHuffman();
}

memset( buf, 0, sizeof( *buf ) );
*buf = {};
buf->data = data;
buf->maxsize = length;
}
Expand All @@ -69,7 +69,7 @@ void MSG_InitOOB( msg_t *buf, byte *data, int length )
MSG_initHuffman();
}

memset( buf, 0, sizeof( *buf ) );
*buf = {};
buf->data = data;
buf->maxsize = length;
buf->oob = true;
Expand Down Expand Up @@ -1088,7 +1088,7 @@ void MSG_ReadDeltaEntity( msg_t *msg, const entityState_t *from, entityState_t *
// check for a remove
if ( MSG_ReadBits( msg, 1 ) == 1 )
{
memset( to, 0, sizeof( *to ) );
*to = {};
to->number = MAX_GENTITIES - 1;

if ( cl_shownet && ( cl_shownet->integer >= 2 || cl_shownet->integer == -1 ) )
Expand Down
4 changes: 2 additions & 2 deletions src/engine/qcommon/net_chan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ called to open a channel to a remote system
*/
void Netchan_Setup( netsrc_t sock, netchan_t *chan, const netadr_t& adr, int qport )
{
memset( chan, 0, sizeof( *chan ) );
ResetStruct( *chan );

chan->sock = sock;
chan->remoteAddress = adr;
Expand Down Expand Up @@ -476,7 +476,7 @@ bool NET_GetLoopPacket( netsrc_t sock, netadr_t *net_from, msg_t *net_mes

memcpy( net_message->data, loop->msgs[ i ].data, loop->msgs[ i ].datalen );
net_message->cursize = loop->msgs[ i ].datalen;
memset( net_from, 0, sizeof( *net_from ) );
*net_from = {};
net_from->type = netadrtype_t::NA_LOOPBACK;
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/engine/renderer/tr_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2269,7 +2269,7 @@ static void RB_RenderInteractionsShadowMapped()
else
{
// set up the transformation matrix
memset( &backEnd.orientation, 0, sizeof( backEnd.orientation ) );
backEnd.orientation = {};

backEnd.orientation.axis[ 0 ][ 0 ] = 1;
backEnd.orientation.axis[ 1 ][ 1 ] = 1;
Expand Down Expand Up @@ -2448,7 +2448,7 @@ static void RB_RenderInteractionsShadowMapped()
else
{
// set up the transformation matrix
memset( &backEnd.orientation, 0, sizeof( backEnd.orientation ) );
backEnd.orientation = {};

backEnd.orientation.axis[ 0 ][ 0 ] = 1;
backEnd.orientation.axis[ 1 ][ 1 ] = 1;
Expand Down
10 changes: 3 additions & 7 deletions src/engine/renderer/tr_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3381,7 +3381,7 @@ static void R_CreateWorldVBO()
}

vboSurf = ( srfVBOMesh_t * ) ri.Hunk_Alloc( sizeof( *vboSurf ), ha_pref::h_low );
memset( vboSurf, 0, sizeof( *vboSurf ) );
*vboSurf = {};
vboSurf->surfaceType = surfaceType_t::SF_VBO_MESH;

vboSurf->numIndexes = surfIndexes;
Expand Down Expand Up @@ -3649,12 +3649,9 @@ static void R_LoadNodesAndLeafs( lump_t *nodeLump, lump_t *leafLump )
dleaf_t *inLeaf;
bspNode_t *out;
int numNodes, numLeafs;
vboData_t data;

Log::Debug("...loading nodes and leaves" );

memset( &data, 0, sizeof( data ) );

in = ( dnode_t * ) ( void * )( fileBase + nodeLump->fileofs );

if ( nodeLump->filelen % sizeof( dnode_t ) || leafLump->filelen % sizeof( dleaf_t ) )
Expand Down Expand Up @@ -6513,7 +6510,6 @@ void R_BuildCubeMaps()
{
int i;
int ii, jj;
refdef_t rf;
bool flipx;
bool flipy;
int x, y, xy, xy2;
Expand All @@ -6535,7 +6531,7 @@ void R_BuildCubeMaps()

startTime = ri.Milliseconds();

memset( &rf, 0, sizeof( refdef_t ) );
refdef_t rf{};

for ( i = 0; i < 6; i++ )
{
Expand Down Expand Up @@ -6910,7 +6906,7 @@ void RE_LoadWorldMap( const char *name )
tr.worldDeluxeMapping = false;
tr.worldHDR_RGBE = false;

memset( &s_worldData, 0, sizeof( s_worldData ) );
s_worldData = {};
Q_strncpyz( s_worldData.name, name, sizeof( s_worldData.name ) );

Q_strncpyz( s_worldData.baseName, COM_SkipPath( s_worldData.name ), sizeof( s_worldData.name ) );
Expand Down
8 changes: 4 additions & 4 deletions src/engine/renderer/tr_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void R_PerformanceCounters()
if ( !r_speeds->integer )
{
// clear the counters even if we aren't printing
memset( &tr.pc, 0, sizeof( tr.pc ) );
memset( &backEnd.pc, 0, sizeof( backEnd.pc ) );
tr.pc = {};
backEnd.pc = {};
return;
}

Expand Down Expand Up @@ -117,8 +117,8 @@ void R_PerformanceCounters()
tr.pc.c_decalSurfacesCreated );
}

memset( &tr.pc, 0, sizeof( tr.pc ) );
memset( &backEnd.pc, 0, sizeof( backEnd.pc ) );
tr.pc = {};
backEnd.pc = {};
}

/*
Expand Down
Loading

0 comments on commit 6959367

Please sign in to comment.