diff --git a/src/g_game.c b/src/g_game.c index df79f7805..8eb394756 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -5464,33 +5464,36 @@ void G_GhostTicker(void) break; } } - if (type == MT_GHOST) + if (type != -1) { - mobj = P_SpawnGhostMobj(g->mo); // does a large portion of the work for us - mobj->frame = (mobj->frame & ~FF_FRAMEMASK)|tr_trans60<mo->x, g->mo->y, g->mo->z - FixedDiv(FixedMul(g->mo->info->height, g->mo->scale) - g->mo->height,3*FRACUNIT), MT_THOK); - mobj->sprite = states[mobjinfo[type].spawnstate].sprite; - mobj->frame = (states[mobjinfo[type].spawnstate].frame & FF_FRAMEMASK) | tr_trans60<tics = -1; // nope. - mobj->color = g->mo->color; - if (g->mo->eflags & MFE_VERTICALFLIP) + if (type == MT_GHOST) { - mobj->flags2 |= MF2_OBJECTFLIP; - mobj->eflags |= MFE_VERTICALFLIP; + mobj = P_SpawnGhostMobj(g->mo); // does a large portion of the work for us + mobj->frame = (mobj->frame & ~FF_FRAMEMASK)|tr_trans60<mo->scale); - mobj->destscale = g->mo->scale; + else + { + mobj = P_SpawnMobj(g->mo->x, g->mo->y, g->mo->z - FixedDiv(FixedMul(g->mo->info->height, g->mo->scale) - g->mo->height,3*FRACUNIT), MT_THOK); + mobj->sprite = states[mobjinfo[type].spawnstate].sprite; + mobj->frame = (states[mobjinfo[type].spawnstate].frame & FF_FRAMEMASK) | tr_trans60<tics = -1; // nope. + mobj->color = g->mo->color; + if (g->mo->eflags & MFE_VERTICALFLIP) + { + mobj->flags2 |= MF2_OBJECTFLIP; + mobj->eflags |= MFE_VERTICALFLIP; + } + P_SetScale(mobj, g->mo->scale); + mobj->destscale = g->mo->scale; + } + mobj->floorz = mobj->z; + mobj->ceilingz = mobj->z+mobj->height; + P_UnsetThingPosition(mobj); + mobj->flags = MF_NOBLOCKMAP|MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY; // make an ATTEMPT to curb crazy SOCs fucking stuff up... + P_SetThingPosition(mobj); + mobj->fuse = 8; + P_SetTarget(&mobj->target, g->mo); } - mobj->floorz = mobj->z; - mobj->ceilingz = mobj->z+mobj->height; - P_UnsetThingPosition(mobj); - mobj->flags = MF_NOBLOCKMAP|MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY; // make an ATTEMPT to curb crazy SOCs fucking stuff up... - P_SetThingPosition(mobj); - mobj->fuse = 8; - P_SetTarget(&mobj->target, g->mo); } if (ziptic & EZT_HIT) { // Spawn hit poofs for killing things! @@ -8141,7 +8144,7 @@ void G_SaveDemo(void) size_t i, strindex = 0; boolean dash = true; - for (i = 0; i < 127 && demo.titlename[i]; i++) + for (i = 0; demo.titlename[i] && i < 127; i++) { if ((demo.titlename[i] >= 'a' && demo.titlename[i] <= 'z') || (demo.titlename[i] >= '0' && demo.titlename[i] <= '9')) diff --git a/src/g_input.c b/src/g_input.c index 43b7f48ca..8d5b38bf2 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -1030,7 +1030,7 @@ INT32 G_KeyStringtoNum(const char *keystr) if (!keystr[0]) return 0; - if (!keystr[0] || (!keystr[1] && keystr[0] > ' ' && keystr[0] <= 'z')) + if (!keystr[1] && keystr[0] > ' ' && keystr[0] <= 'z') return keystr[0]; if (!strncmp(keystr, "KEY", 3) && keystr[3] >= '0' && keystr[3] <= '9') diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index e25364bee..43cb25aed 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4464,7 +4464,10 @@ static void HWR_DrawModels(void) continue; } - if (spr->mobj && spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) + if (!spr->mobj) + continue; + + if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) { md2_t *md2; diff --git a/src/k_kart.c b/src/k_kart.c index e5fbf69ec..b98103761 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -10527,11 +10527,12 @@ static void K_drawKartWanted(void) { INT32 x = basex+(splitscreen > 1 ? 13 : 8), y = basey+(splitscreen > 1 ? 16 : 21); fixed_t scale = FRACUNIT/2; - player_t *p = &players[battlewanted[i]]; if (battlewanted[i] == -1) break; + player_t *p = &players[battlewanted[i]]; + if (numwanted == 1) scale = FRACUNIT; else @@ -10542,7 +10543,7 @@ static void K_drawKartWanted(void) y += 16; } - if (players[battlewanted[i]].skincolor) + if (p->skincolor) { colormap = R_GetTranslationColormap(TC_RAINBOW, p->skincolor, GTC_CACHE); V_DrawFixedPatch(x<8) + + if (texturesTokenLength > 8) { I_Error("Error parsing TEXTURES lump: Patch name \"%s\" exceeds 8 characters",texturesToken); } @@ -801,10 +804,12 @@ static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch) // Comma 1 Z_Free(texturesToken); texturesToken = M_GetToken(NULL); + if (texturesToken == NULL) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where comma after \"%s\"'s patch name should be",patchName); } + if (strcmp(texturesToken,",")!=0) { I_Error("Error parsing TEXTURES lump: Expected \",\" after %s's patch name, got \"%s\"",patchName,texturesToken); @@ -813,14 +818,17 @@ static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch) // XPos Z_Free(texturesToken); texturesToken = M_GetToken(NULL); + if (texturesToken == NULL) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where patch \"%s\"'s x coordinate should be",patchName); } + endPos = NULL; #ifndef AVOID_ERRNO errno = 0; #endif + patchXPos = strtol(texturesToken,&endPos,10); (void)patchXPos; //unused for now if (endPos == texturesToken // Empty string @@ -836,10 +844,12 @@ static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch) // Comma 2 Z_Free(texturesToken); texturesToken = M_GetToken(NULL); + if (texturesToken == NULL) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where comma after patch \"%s\"'s x coordinate should be",patchName); } + if (strcmp(texturesToken,",")!=0) { I_Error("Error parsing TEXTURES lump: Expected \",\" after patch \"%s\"'s x coordinate, got \"%s\"",patchName,texturesToken); @@ -848,6 +858,7 @@ static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch) // YPos Z_Free(texturesToken); texturesToken = M_GetToken(NULL); + if (texturesToken == NULL) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where patch \"%s\"'s y coordinate should be",patchName); @@ -1220,9 +1231,9 @@ static void R_InitExtraColormaps(void) lumpnum_t R_GetFlatNumForName(const char *name) { INT32 i; - lumpnum_t lump; - lumpnum_t start; - lumpnum_t end; + lumpnum_t lump = LUMPERROR; + lumpnum_t start = LUMPERROR; + lumpnum_t end = LUMPERROR; // Scan wad files backwards so patched flats take preference. for (i = numwadfiles - 1; i >= 0; i--) @@ -1697,7 +1708,7 @@ const char *R_ColormapNameForNum(INT32 num) if (num == -1) return "NONE"; - if (num < 0 || num > MAXCOLORMAPS) + if (num < 0 || num >= MAXCOLORMAPS) I_Error("R_ColormapNameForNum: num %d is invalid!\n", num); if (foundcolormaps[num] == LUMPERROR) diff --git a/src/w_wad.c b/src/w_wad.c index 0bb741a59..bf9389986 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -2043,8 +2043,7 @@ static lumpchecklist_t folderblacklist[] = {NULL, 0}, }; -static int -W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status) +static int W_VerifyPK3(FILE *fp, lumpchecklist_t *checklist, boolean status) { int verified = true; @@ -2086,7 +2085,10 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status) char *cdir = (char*)(malloc(LONG(zend.cdirsize))); if (fread(cdir, 1, LONG(zend.cdirsize), fp) < (UINT32)(LONG(zend.cdirsize))) + { + free(cdir); return true; + } size_t offset = 0; @@ -2098,7 +2100,10 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status) char* dotpos; if (memcmp(zentry->signature, pat_central, 4) != 0) + { + free(cdir); return true; + } if (verified == true) { @@ -2136,10 +2141,16 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status) sizeof *zentry + SHORT(zentry->namelen) + SHORT(zentry->xtralen) + SHORT(zentry->commlen); if (fseek(fp, LONG(zentry->offset), SEEK_SET) != 0) + { + free(cdir); return true; + } if (fread(&zlentry, 1, sizeof(zlentry_t), fp) < sizeof (zlentry_t)) + { + free(cdir); return true; + } data_size += sizeof zlentry + SHORT(zlentry.namelen) + SHORT(zlentry.xtralen) + LONG(zlentry.compsize); @@ -2190,7 +2201,9 @@ static int W_VerifyFile(const char *filename, lumpchecklist_t *checklist, goodfile = W_VerifyWAD(handle, checklist, status); } } + fclose(handle); + return goodfile; } @@ -2345,7 +2358,10 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist) char *cdir = (char*)(malloc(LONG(zend.cdirsize))); if (fread(cdir, 1, LONG(zend.cdirsize), fp) < (UINT32)(LONG(zend.cdirsize))) + { + free(cdir); return true; + } size_t offset = 0; @@ -2357,7 +2373,10 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist) char* dotpos; if (memcmp(zentry->signature, pat_central, 4) != 0) + { + free(cdir); return false; + } fullname = (char*)(malloc(SHORT(zentry->namelen) + 1)); strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); @@ -2377,11 +2396,19 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist) strncpy(lumpname, trimname, min(8, dotpos - trimname)); if (W_NameStartsWith(lumpname, checklist)) + { + free(fullname); + free(cdir); return true; + } } if (W_NameStartsWith(fullname, checklist)) + { + free(fullname); + free(cdir); return true; + } free(fullname); @@ -2391,10 +2418,16 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist) sizeof *zentry + SHORT(zentry->namelen) + SHORT(zentry->xtralen) + SHORT(zentry->commlen); if (fseek(fp, LONG(zentry->offset), SEEK_SET) != 0) + { + free(cdir); return false; + } if (fread(&zlentry, 1, sizeof(zlentry_t), fp) < sizeof (zlentry_t)) + { + free(cdir); return false; + } data_size += sizeof zlentry + SHORT(zlentry.namelen) + SHORT(zlentry.xtralen) + LONG(zlentry.compsize);