Fixes resulting from code analysis

This commit is contained in:
Walter Julius Hennecke 2013-04-13 01:34:37 +02:00
parent 64a8d2a026
commit 1e8e349d2b
11 changed files with 54 additions and 22 deletions

View file

@ -1561,7 +1561,7 @@ static gender_t G_ParseAnimationFileSex( const char *filename) {
char *text_p;
int len;
char *token;
char text[20000];
char text[20000]; // TODO move to heap?
fileHandle_t f;
char animfile[MAX_QPATH];
@ -1703,7 +1703,7 @@ char* BG_RegisterRace( const char *name ) {
qboolean BG_ParseRankNames( char* fileName, rankNames_t rankNames[] ) {
fileHandle_t f;
int file_len;
char charText[20000];
char charText[20000]; // TODO move to heap?
char* textPtr;
char* token;
int i = 0;
@ -1762,6 +1762,7 @@ qboolean BG_ParseRankNames( char* fileName, rankNames_t rankNames[] ) {
/* If we hit an open brace (ie, assuming we hit the start of a new rank cell) */
if ( !Q_stricmpn( token, "{", 1 ) ) {
while ( 1 ) {
token = COM_Parse( &textPtr );
if( !token[0] ) {
break;

View file

@ -1750,7 +1750,7 @@ void G_Client_Begin( int clientNum, qboolean careAboutWarmup, qboolean isBot, qb
int len;
fileHandle_t file;
char *p, *q;
char buf[16000];
char buf[16000]; // TODO move to heap ?
len = trap_FS_FOpenFile( rpg_motdFile.string, &file, FS_READ );
if (!file || !len) {

View file

@ -300,6 +300,10 @@ static void Cmd_Give_f( gentity_t *ent ) {
for ( i = bg_numGiveItems - 1; i > -1; i-- ) {
item = &bg_giveItem[i];
if(item == NULL) {
continue;
}
if ( !Q_stricmp( arg, item->consoleName ) ) {
break;
}
@ -317,6 +321,10 @@ static void Cmd_Give_f( gentity_t *ent ) {
//Fuck this. Why does ioEF crash if you don't break a case statement with code in it? :S
if(item == NULL) {
return;
}
switch ( item->giveType ) {
case TYPE_ALL:
targEnt->health = ps->stats[STAT_MAX_HEALTH];
@ -1566,17 +1574,17 @@ static void Cmd_SayArea( gentity_t *ent, char* text)
OtherPlayer = &g_entities[i]; //Point OtherPlayer to next player
//Send message to admins warning about command being used.
//TiM - since double spamming is annoying, ensure that the target admin wants this alert
if ( !OtherPlayer->client->noAdminChat )
G_SayTo( ent, OtherPlayer, SAY_ADMIN, COLOR_CYAN, va("%s ^7said to area: ", pers->netname ), text ); //^2%s
//Check is OtherPlayer is valid
if ( !OtherPlayer || !OtherPlayer->inuse || !OtherPlayer->client )
{
continue;
}
//Send message to admins warning about command being used.
//TiM - since double spamming is annoying, ensure that the target admin wants this alert
if ( !OtherPlayer->client->noAdminChat )
G_SayTo( ent, OtherPlayer, SAY_ADMIN, COLOR_CYAN, va("%s ^7said to area: ", pers->netname ), text ); //^2%s
//TiM - I have a better solution. the trap_inPVS function lets u see if two points are within the same Vis cluster
//in the BSP tree. That should mean as long as they're in the same room, regardless if they can see each other or not,
//they'll get the message
@ -2220,6 +2228,10 @@ static void Cmd_ForceKill_f( gentity_t *ent ) {
}
} // end iterations
if(target == NULL) {
return;
}
Com_sprintf (send, sizeof(send), "%s ^7forced %s^7's death", ent->client->pers.netname, target->client->pers.netname);
for (j = 0; j < MAX_CLIENTS - 1; j++) {
@ -3725,7 +3737,7 @@ static void Cmd_EntList_f ( gentity_t *ent ) {
Com_sprintf( entBuffer, sizeof( entBuffer ), "ClassName: '%s', ID: %i\n", mapEnt->classname, i);
}
if ( strlen(mainBuffer) + strlen(entBuffer) > sizeof( mainBuffer ) ) {
if ( strlen(mainBuffer) + strlen(entBuffer) >= sizeof( mainBuffer ) ) {
break;
}
else {
@ -5262,7 +5274,7 @@ static void Cmd_MapsList_f( gentity_t *ent )
continue;
}
if ( strlen(mapList) + len + 20 > sizeof( mapList ) )
if ( strlen(mapList) + len + 20 >= sizeof( mapList ) )
break;
Q_strcat( mapList, sizeof( mapList ), filePtr );

View file

@ -1113,7 +1113,7 @@ void G_Damage( gentity_t *targ, gentity_t *inflictor, gentity_t *attacker,
if ( client )
{
if ( client->noclip ) {
if ( client == NULL || client->noclip ) {
return;
}
}

View file

@ -2621,6 +2621,7 @@ void G_RunThink (gentity_t *ent) {
ent->nextthink = 0;
if (!ent->think) {
G_Error ( "NULL ent->think");
return;
}
#ifdef G_LUA

View file

@ -607,10 +607,12 @@ void Svcmd_EntityList_f (void) {
gentity_t *check;
char arg[MAX_QPATH*4];
int length = 0;
qboolean args = qfalse;
if(trap_Argc() > 1) {
trap_Argv(1, arg, sizeof(arg));
length = strlen(arg);
args = qtrue;
}
check = g_entities+1;
@ -618,7 +620,7 @@ void Svcmd_EntityList_f (void) {
if ( !check->inuse ) {
continue;
}
if(!arg[0]) {
if(args == qfalse) {
if ( check->classname && Q_stricmpn(check->classname, "noclass", 7) && Q_stricmpn(check->classname, "bodyque", 7) ) {
G_Printf("%3i:", e);
switch ( check->s.eType ) {

View file

@ -1644,6 +1644,10 @@ void SP_target_turbolift ( gentity_t *self )
char mapRoute[MAX_QPATH];
char serverInfo[MAX_TOKEN_CHARS];
if(self == NULL) {
return;
}
//cache the moving sounds
G_SpawnString( "soundLoop", "sound/movers/plats/turbomove.wav", &loopSound );
G_SpawnString( "soundEnd", "sound/movers/plats/turbostop.wav", &endSound );

View file

@ -364,7 +364,7 @@ void Use_target_push( gentity_t *self, gentity_t *other, gentity_t *activator )
}
/* RPG-X: J2J noclip use */
if ( activator->client->ps.pm_type != PM_NORMAL || activator->client->ps.pm_type != PM_NOCLIP) {
if ( (activator->client->ps.pm_type != PM_NORMAL) || (activator->client->ps.pm_type != PM_NOCLIP)) {
return;
}

View file

@ -78,8 +78,8 @@ static int Entity_MMBRefit(lua_State * L)
// returns a target entity of ent
static int Entity_GetTarget(lua_State * L)
{
lent_t *lent;
gentity_t *t = NULL;
lent_t* lent = NULL;
gentity_t* t = NULL;
lent = Lua_GetEntity(L, 1);
t = G_PickTarget(lent->e->target);
@ -530,8 +530,12 @@ static int Entity_CallSpawn(lua_State *L) {
lent = Lua_GetEntity(L, 1);
if(lent)
if(lent != NULL) {
e = lent->e;
} else {
lua_pushboolean(L, qfalse);
return 1;
}
if(!Q_stricmp(lent->e->classname, "target_selfdestruct"))
return 1; //we will not selfdestruct this way
@ -766,7 +770,10 @@ static int Entity_IsLocked(lua_State *L) {
lent = Lua_GetEntity(L, 1);
if(!lent || lent->e) return 1;
if(lent == NULL || lent->e == NULL) {
lua_pushnil(L);
return 1;
}
ent = lent->e;
@ -1176,8 +1183,9 @@ static int Entity_SetEnemy(lua_State *L) {
lent_t *enemy;
lent = Lua_GetEntity(L, 1);
if(!lent || lent->e)
if(lent == NULL || lent->e == NULL) {
return 1;
}
if(lua_isnil(L, 2)) {
lent->e->enemy = NULL;
} else {
@ -1782,7 +1790,7 @@ static int Entity_GetModel(lua_State *L) {
lent_t *lent;
lent = Lua_GetEntity(L, 1);
if(!lent || lent->e)
if(lent == NULL || lent->e == NULL)
lua_pushnil(L);
else
lua_pushstring(L, lent->e->model);

View file

@ -110,7 +110,7 @@ static int Mover_AsTrain(lua_State * L)
if(!targ) return 1;
} else {
tlent = Lua_GetEntity(L, 2);
if(!tlent || tlent->e) return 1;
if(!tlent || tlent->e == NULL) return 1;
targ = tlent->e;
}

View file

@ -918,6 +918,10 @@ char *Q_CleanStr( char *string ) {
char* s;
int c;
if(string == NULL) {
return string;
}
s = string;
d = string;
while ((c = *s) != 0 ) {
@ -1162,8 +1166,8 @@ Info_RemoveKey_Big
*/
void Info_RemoveKey_Big( char *s, const char *key ) {
char *start;
char pkey[BIG_INFO_KEY];
char value[BIG_INFO_VALUE];
char pkey[BIG_INFO_KEY]; // TODO move to heap?
char value[BIG_INFO_VALUE]; // TODO move to heap?
char *o;
if ( strlen( s ) >= BIG_INFO_STRING ) {