replace instances of malloc + memset with calloc
This commit is contained in:
1 parent
ed527a35e2
commit
e63c6cfd1e
9 files changed
+82
-74
No files matched your search
@@ -3287,6 +3287,7 @@ void CL_ClearPlayer(INT32 playernum)
|
||||
P_RemoveMobj(players[playernum].mo->tracer);
|
||||
P_RemoveMobj(players[playernum].mo);
|
||||
}
|
||||
|
||||
memset(&players[playernum], 0, sizeof (player_t));
|
||||
}
|
||||
|
||||
@@ -5136,6 +5137,7 @@ static void PT_ServerCFG(SINT8 node)
|
||||
SendSaturnInfo(node);
|
||||
#endif
|
||||
memset(playeringame, 0, sizeof(playeringame));
|
||||
|
||||
for (j = 0; j < MAXPLAYERS; j++)
|
||||
{
|
||||
if (netbuffer->u.servercfg.playerskins[j] == 0xFF
|
||||
@@ -6557,6 +6559,7 @@ static inline void PingUpdate(void)
|
||||
INT32 i;
|
||||
UINT8 pingkick[MAXPLAYERS];
|
||||
UINT8 nonlaggers = 0;
|
||||
|
||||
memset(pingkick, 0, sizeof(pingkick));
|
||||
|
||||
doomdata_t *netbuffer = DOOMCOM_DATA(doomcom);
|
||||
|
||||
+2
-8
@@ -658,13 +658,10 @@ static boolean SV_SendFile(INT32 node, const char *filename, UINT8 fileid)
|
||||
q = &((*q)->next);
|
||||
|
||||
// Allocate a file request and append it to the file list
|
||||
p = *q = (filetx_t *)malloc(sizeof (filetx_t));
|
||||
p = *q = (filetx_t *)calloc(1, sizeof(filetx_t)); // Initialise with zeros
|
||||
if (!p)
|
||||
I_Error("SV_SendFile: No more memory\n");
|
||||
|
||||
// Initialise with zeros
|
||||
memset(p, 0, sizeof (filetx_t));
|
||||
|
||||
// Allocate the file name
|
||||
p->id.filename = (char *)malloc(MAX_WADPATH);
|
||||
if (!p->id.filename)
|
||||
@@ -743,13 +740,10 @@ void SV_SendRam(INT32 node, void *data, size_t size, freemethod_t freemethod, UI
|
||||
q = &((*q)->next);
|
||||
|
||||
// Allocate a file request and append it to the file list
|
||||
p = *q = (filetx_t *)malloc(sizeof (filetx_t));
|
||||
p = *q = (filetx_t *)calloc(1, sizeof(filetx_t)); // Initialise with zeros
|
||||
if (!p)
|
||||
I_Error("SV_SendRam: No more memory\n");
|
||||
|
||||
// Initialise with zeros
|
||||
memset(p, 0, sizeof (filetx_t));
|
||||
|
||||
p->ram = freemethod; // Remember how to free the memory block for when we're done sending it
|
||||
p->id.ram = data;
|
||||
p->size = (UINT32)size;
|
||||
|
||||
+1
-1
@@ -149,7 +149,7 @@ static UINT8 F_WriteText(void)
|
||||
static void F_NewCutscene(const char *basetext)
|
||||
{
|
||||
cutscene_basetext = basetext;
|
||||
memset(cutscene_disptext,0,sizeof(cutscene_disptext));
|
||||
memset(cutscene_disptext, 0, sizeof(cutscene_disptext));
|
||||
cutscene_writeptr = cutscene_baseptr = 0;
|
||||
cutscene_textspeed = 9;
|
||||
cutscene_textcount = TICRATE/2;
|
||||
|
||||
@@ -303,6 +303,7 @@ static void CalcFillCoords(drawitem_t *item)
|
||||
else if (!(c & V_SNAPTOLEFT))
|
||||
x += (vid.width - (BASEVIDWIDTH * dupx)) / 2;
|
||||
}
|
||||
|
||||
if (vid.height != BASEVIDHEIGHT * dupy)
|
||||
{
|
||||
// same thing here
|
||||
@@ -311,6 +312,7 @@ static void CalcFillCoords(drawitem_t *item)
|
||||
else if (!(c & V_SNAPTOTOP))
|
||||
y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2;
|
||||
}
|
||||
|
||||
if (c & V_SPLITSCREEN)
|
||||
y += (BASEVIDHEIGHT * dupy)/2;
|
||||
if (c & V_HORZSCREEN)
|
||||
@@ -346,6 +348,7 @@ static UINT64 GetItemId(void)
|
||||
id |= INTERP_LATCH;
|
||||
hud_interplatch = false;
|
||||
}
|
||||
|
||||
if (hud_interpstring)
|
||||
id |= INTERP_STRING;
|
||||
|
||||
|
||||
+4
-4
@@ -154,7 +154,7 @@ static int lib_setState(lua_State *L)
|
||||
return luaL_error(L, "Do not alter states in BuildCMD code!");
|
||||
|
||||
// clear the state to start with, in case of missing table elements
|
||||
memset(state,0,sizeof(state_t));
|
||||
memset(state, 0, sizeof(state_t));
|
||||
state->tics = -1;
|
||||
|
||||
lua_pushnil(L);
|
||||
@@ -262,8 +262,8 @@ boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor)
|
||||
return false; // action not called.
|
||||
|
||||
if (superstack && fasticmp(actionpointers[actionnum].name, superactions[superstack-1])) // the action is calling itself,
|
||||
return false; // let it call the hardcoded function
|
||||
|
||||
return false; // let it call the hardcoded function
|
||||
|
||||
lua_pushcfunction(gL, LUA_GetErrorMessage);
|
||||
|
||||
// grab function by uppercase name.
|
||||
@@ -514,7 +514,7 @@ static int lib_setMobjInfo(lua_State *L)
|
||||
return luaL_error(L, "Do not alter mobjinfo in BuildCMD code!");
|
||||
|
||||
// clear the mobjinfo to start with, in case of missing table elements
|
||||
memset(info,0,sizeof(mobjinfo_t));
|
||||
memset(info, 0, sizeof(mobjinfo_t));
|
||||
info->doomednum = -1; // default to no editor value
|
||||
info->spawnhealth = 1; // avoid 'dead' noclip behaviors
|
||||
|
||||
|
||||
+4
-7
@@ -848,8 +848,7 @@ static polymaplink_t *Polyobj_getLink(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
l = Z_Malloc(sizeof(*l), PU_LEVEL, NULL);
|
||||
memset(l, 0, sizeof(*l));
|
||||
l = Z_Calloc(sizeof(*l), PU_LEVEL, NULL);
|
||||
}
|
||||
|
||||
return l;
|
||||
@@ -1565,8 +1564,7 @@ void Polyobj_InitLevel(void)
|
||||
{
|
||||
++numPolyObjects;
|
||||
|
||||
qitem = malloc(sizeof(mobjqitem_t));
|
||||
memset(qitem, 0, sizeof(mobjqitem_t));
|
||||
qitem = calloc(1, sizeof(mobjqitem_t));
|
||||
qitem->mo = mo;
|
||||
M_QueueInsert(&(qitem->mqitem), &spawnqueue);
|
||||
}
|
||||
@@ -1574,8 +1572,7 @@ void Polyobj_InitLevel(void)
|
||||
{
|
||||
++numAnchors;
|
||||
|
||||
qitem = malloc(sizeof(mobjqitem_t));
|
||||
memset(qitem, 0, sizeof(mobjqitem_t));
|
||||
qitem = calloc(1, sizeof(mobjqitem_t));
|
||||
qitem->mo = mo;
|
||||
M_QueueInsert(&(qitem->mqitem), &anchorqueue);
|
||||
}
|
||||
@@ -2466,7 +2463,7 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata)
|
||||
R_CreateInterpolator_Polyobj(&th->thinker, po);
|
||||
// T_PolyObjWaypoint is the only polyobject movement
|
||||
// that can adjust z, so we add these ones too.
|
||||
R_CreateInterpolator_SectorPlane(&th->thinker, po->lines[0]->backsector, false);
|
||||
R_CreateInterpolator_SectorPlane(&th->thinker, po->lines[0]->backsector, false);
|
||||
R_CreateInterpolator_SectorPlane(&th->thinker, po->lines[0]->backsector, true);
|
||||
|
||||
// Most other polyobject functions handle children by recursively
|
||||
|
||||
+63
-53
@@ -181,54 +181,60 @@ void P_RunDynamicSlopes(void)
|
||||
{
|
||||
pslope_t *slope;
|
||||
|
||||
for (slope = slopelist; slope; slope = slope->next) {
|
||||
for (slope = slopelist; slope; slope = slope->next)
|
||||
{
|
||||
fixed_t zdelta;
|
||||
|
||||
if (slope->flags & SL_NODYNAMIC)
|
||||
continue;
|
||||
|
||||
switch(slope->refpos) {
|
||||
case 1: // front floor
|
||||
zdelta = slope->sourceline->backsector->floorheight - slope->sourceline->frontsector->floorheight;
|
||||
slope->o.z = slope->sourceline->frontsector->floorheight;
|
||||
break;
|
||||
case 2: // front ceiling
|
||||
zdelta = slope->sourceline->backsector->ceilingheight - slope->sourceline->frontsector->ceilingheight;
|
||||
slope->o.z = slope->sourceline->frontsector->ceilingheight;
|
||||
break;
|
||||
case 3: // back floor
|
||||
zdelta = slope->sourceline->frontsector->floorheight - slope->sourceline->backsector->floorheight;
|
||||
slope->o.z = slope->sourceline->backsector->floorheight;
|
||||
break;
|
||||
case 4: // back ceiling
|
||||
zdelta = slope->sourceline->frontsector->ceilingheight - slope->sourceline->backsector->ceilingheight;
|
||||
slope->o.z = slope->sourceline->backsector->ceilingheight;
|
||||
break;
|
||||
case 5: // vertices
|
||||
{
|
||||
mapthing_t *mt;
|
||||
size_t i;
|
||||
INT32 l;
|
||||
line_t *line;
|
||||
switch(slope->refpos)
|
||||
{
|
||||
case 1: // front floor
|
||||
zdelta = slope->sourceline->backsector->floorheight - slope->sourceline->frontsector->floorheight;
|
||||
slope->o.z = slope->sourceline->frontsector->floorheight;
|
||||
break;
|
||||
case 2: // front ceiling
|
||||
zdelta = slope->sourceline->backsector->ceilingheight - slope->sourceline->frontsector->ceilingheight;
|
||||
slope->o.z = slope->sourceline->frontsector->ceilingheight;
|
||||
break;
|
||||
case 3: // back floor
|
||||
zdelta = slope->sourceline->frontsector->floorheight - slope->sourceline->backsector->floorheight;
|
||||
slope->o.z = slope->sourceline->backsector->floorheight;
|
||||
break;
|
||||
case 4: // back ceiling
|
||||
zdelta = slope->sourceline->frontsector->ceilingheight - slope->sourceline->backsector->ceilingheight;
|
||||
slope->o.z = slope->sourceline->backsector->ceilingheight;
|
||||
break;
|
||||
case 5: // vertices
|
||||
{
|
||||
mapthing_t *mt;
|
||||
size_t i;
|
||||
INT32 l;
|
||||
line_t *line;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
mt = slope->vertices[i];
|
||||
l = P_FindSpecialLineFromTag(799, mt->angle, -1);
|
||||
if (l != -1) {
|
||||
line = &lines[l];
|
||||
mt->z = line->frontsector->floorheight >> FRACBITS;
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
mt = slope->vertices[i];
|
||||
l = P_FindSpecialLineFromTag(799, mt->angle, -1);
|
||||
|
||||
if (l != -1)
|
||||
{
|
||||
line = &lines[l];
|
||||
mt->z = line->frontsector->floorheight >> FRACBITS;
|
||||
}
|
||||
}
|
||||
|
||||
P_ReconfigureVertexSlope(slope);
|
||||
}
|
||||
continue; // TODO
|
||||
|
||||
P_ReconfigureVertexSlope(slope);
|
||||
}
|
||||
continue; // TODO
|
||||
|
||||
default:
|
||||
I_Error("P_RunDynamicSlopes: slope has invalid type!");
|
||||
default:
|
||||
I_Error("P_RunDynamicSlopes: slope has invalid type!");
|
||||
}
|
||||
|
||||
if (slope->zdelta != FixedDiv(zdelta, slope->extent)) {
|
||||
if (slope->zdelta != FixedDiv(zdelta, slope->extent))
|
||||
{
|
||||
slope->zdelta = FixedDiv(zdelta, slope->extent);
|
||||
slope->zangle = R_PointToAngle2(0, 0, slope->extent, -zdelta);
|
||||
slope->real_zangle = slope->zangle;
|
||||
@@ -245,8 +251,7 @@ void P_RunDynamicSlopes(void)
|
||||
static pslope_t *P_MakeSlope(const vector3_t *o, const vector2_t *d,
|
||||
const fixed_t zdelta, UINT8 flags)
|
||||
{
|
||||
pslope_t *ret = Z_Malloc(sizeof(pslope_t), PU_LEVEL, NULL);
|
||||
memset(ret, 0, sizeof(*ret));
|
||||
pslope_t *ret = Z_Calloc(sizeof(pslope_t), PU_LEVEL, NULL);
|
||||
|
||||
ret->o.x = o->x;
|
||||
ret->o.y = o->y;
|
||||
@@ -340,13 +345,13 @@ void P_SpawnSlope_Line(int linenum)
|
||||
if (line->flags & ML_NOKNUX)
|
||||
flags |= SL_ANCHORVERTEX;
|
||||
|
||||
if(!frontfloor && !backfloor && !frontceil && !backceil)
|
||||
if (!frontfloor && !backfloor && !frontceil && !backceil)
|
||||
{
|
||||
CONS_Printf("P_SpawnSlope_Line called with non-slope line special.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!line->frontsector || !line->backsector)
|
||||
if (!line->frontsector || !line->backsector)
|
||||
{
|
||||
CONS_Debug(DBG_SETUP, "P_SpawnSlope_Line used on a line without two sides. (line number %i)\n", linenum);
|
||||
return;
|
||||
@@ -626,15 +631,13 @@ static pslope_t *P_NewVertexSlope(INT16 tag1, INT16 tag2, INT16 tag3, UINT8 flag
|
||||
size_t i;
|
||||
mapthing_t *mt = mapthings;
|
||||
|
||||
pslope_t *ret = Z_Malloc(sizeof(pslope_t), PU_LEVEL, NULL);
|
||||
memset(ret, 0, sizeof(*ret));
|
||||
pslope_t *ret = Z_Calloc(sizeof(pslope_t), PU_LEVEL, NULL);
|
||||
|
||||
// Start by setting flags
|
||||
ret->flags = flags;
|
||||
|
||||
// Now set up the vertex list
|
||||
ret->vertices = Z_Malloc(3*sizeof(mapthing_t), PU_LEVEL, NULL);
|
||||
memset(ret->vertices, 0, 3*sizeof(mapthing_t));
|
||||
ret->vertices = Z_Calloc(3*sizeof(mapthing_t), PU_LEVEL, NULL);
|
||||
|
||||
// And... look for the vertices in question.
|
||||
for (i = 0; i < nummapthings; i++, mt++)
|
||||
@@ -688,7 +691,7 @@ void P_CopySectorSlope(line_t *line)
|
||||
int i, special = line->special;
|
||||
|
||||
// Check for copy linedefs
|
||||
for(i = -1; (i = P_FindSectorFromLineTag(line, i)) >= 0;)
|
||||
for (i = -1; (i = P_FindSectorFromLineTag(line, i)) >= 0;)
|
||||
{
|
||||
sector_t *srcsec = sectors + i;
|
||||
|
||||
@@ -899,11 +902,14 @@ void P_HandleSlopeLanding(mobj_t *thing, pslope_t *slope)
|
||||
{
|
||||
vector3_t mom; // Ditto.
|
||||
|
||||
if (slope->flags & SL_NOPHYSICS) { // No physics, no need to make anything complicated.
|
||||
if (P_MobjFlip(thing)*(thing->momz) < 0) { // falling, land on slope
|
||||
if (slope->flags & SL_NOPHYSICS) // No physics, no need to make anything complicated.
|
||||
{
|
||||
if (P_MobjFlip(thing)*(thing->momz) < 0) // falling, land on slope
|
||||
{
|
||||
thing->momz = -P_MobjFlip(thing);
|
||||
thing->standingslope = slope;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -913,11 +919,11 @@ void P_HandleSlopeLanding(mobj_t *thing, pslope_t *slope)
|
||||
|
||||
P_ReverseQuantizeMomentumToSlope(&mom, slope);
|
||||
|
||||
if (P_MobjFlip(thing)*mom.z < 0) { // falling, land on slope
|
||||
if (P_MobjFlip(thing)*mom.z < 0) // falling, land on slope
|
||||
{
|
||||
thing->momx = mom.x;
|
||||
thing->momy = mom.y;
|
||||
thing->momz = -P_MobjFlip(thing);
|
||||
|
||||
thing->standingslope = slope;
|
||||
}
|
||||
}
|
||||
@@ -937,7 +943,8 @@ void P_ButteredSlope(mobj_t *mo)
|
||||
if (mo->flags & (MF_NOCLIPHEIGHT|MF_NOGRAVITY))
|
||||
return; // don't slide down slopes if you can't touch them or you're not affected by gravity
|
||||
|
||||
if (mo->player) {
|
||||
if (mo->player)
|
||||
{
|
||||
if (abs(mo->standingslope->zdelta) < FRACUNIT/4 && !(mo->player->pflags & PF_SPINNING))
|
||||
return; // Don't slide on non-steep slopes unless spinning
|
||||
|
||||
@@ -947,9 +954,12 @@ void P_ButteredSlope(mobj_t *mo)
|
||||
|
||||
thrust = FINESINE(mo->standingslope->zangle>>ANGLETOFINESHIFT) * 15 / 16 * (mo->eflags & MFE_VERTICALFLIP ? 1 : -1);
|
||||
|
||||
if (mo->player && (mo->player->pflags & PF_SPINNING)) {
|
||||
if (mo->player && (mo->player->pflags & PF_SPINNING))
|
||||
{
|
||||
fixed_t mult = 0;
|
||||
if (mo->momx || mo->momy) {
|
||||
|
||||
if (mo->momx || mo->momy)
|
||||
{
|
||||
angle_t angle = R_PointToAngle2(0, 0, mo->momx, mo->momy) - mo->standingslope->xydirection;
|
||||
|
||||
if (P_MobjFlip(mo) * mo->standingslope->zdelta < 0)
|
||||
|
||||
@@ -827,6 +827,7 @@ void P_PreTicker(INT32 frames)
|
||||
LUA_HOOK(PreThinkFrame);
|
||||
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
{
|
||||
if (playeringame[i] && players[i].mo && !P_MobjWasRemoved(players[i].mo))
|
||||
{
|
||||
// stupid fucking cmd hack
|
||||
@@ -841,6 +842,7 @@ void P_PreTicker(INT32 frames)
|
||||
|
||||
memcpy(&players[i].cmd, &temptic, sizeof(ticcmd_t));
|
||||
}
|
||||
}
|
||||
|
||||
// Dynamic slopeness
|
||||
if (midgamejoin)
|
||||
|
||||
@@ -452,7 +452,6 @@ static UINT8* RGetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 f
|
||||
|
||||
if (flags & GTC_CACHE)
|
||||
{
|
||||
|
||||
// Allocate table for skin if necessary
|
||||
if (!tt[skintableindex])
|
||||
tt[skintableindex] = Z_Calloc(MAXTRANSLATIONS * sizeof(UINT8**), PU_STATIC, NULL);
|
||||
|
||||
Reference in new issue
Block a user