diff --git a/source/games/blood/src/barf.cpp b/source/games/blood/src/barf.cpp index a707d315d..0dc520940 100644 --- a/source/games/blood/src/barf.cpp +++ b/source/games/blood/src/barf.cpp @@ -576,6 +576,7 @@ void ParseScript(int lumpnum) rfs.SkipBeyondValue('\n'); } } + [[fallthrough]]; } case kTagResource: // really light blue.. { diff --git a/source/games/blood/src/blood.cpp b/source/games/blood/src/blood.cpp index 98f0078a1..39a7c0057 100644 --- a/source/games/blood/src/blood.cpp +++ b/source/games/blood/src/blood.cpp @@ -314,7 +314,7 @@ void GameInterface::Ticker() for (int i = 0; i < 8; i++) { - team_ticker[i] = team_ticker[i] -= 4; + team_ticker[i] -= 4; if (team_ticker[i] < 0) team_ticker[i] = 0; } diff --git a/source/games/blood/src/messages.cpp b/source/games/blood/src/messages.cpp index 42fa602ca..8718c7343 100644 --- a/source/games/blood/src/messages.cpp +++ b/source/games/blood/src/messages.cpp @@ -266,7 +266,7 @@ static int parseArgs(char *pzArgs, int *nArg1, int *nArg2) { if (!nArg1 || !nArg2 || strlen(pzArgs) < 3) return -1; - *nArg1 = pzArgs[0] - '0'; + *nArg1 = pzArgs[0] - '0'; int a1 = pzArgs[1] == ' ' ? 0 : pzArgs[1] - '0'; *nArg2 = a1 * 10 + (pzArgs[2] - '0'); return 2; diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index eff55c0ae..e782b5803 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -493,7 +493,7 @@ void nnExtResetGlobals() memset(gImpactSpritesList, 0, sizeof(gImpactSpritesList)); // reset tracking conditions, if any - for (int i = 0; i < countof(gCondition); i++) + for (size_t i = 0; i < countof(gCondition); i++) { TRCONDITION* pCond = &gCondition[i]; for (unsigned k = 0; k < kMaxTracedObjects; k++) @@ -2601,7 +2601,7 @@ void usePropertiesChanger(DBloodActor* sourceactor, int objType, int objIndex, D // data3 = set wall hitag if (valueIsBetween(pXSource->data3, -1, 32767)) { - if ((pSource->flags & kModernTypeFlag1)) pWall->hitag = pWall->hitag |= pXSource->data3; + if ((pSource->flags & kModernTypeFlag1)) pWall->hitag |= pXSource->data3; else pWall->hitag = pXSource->data3; } @@ -2611,7 +2611,7 @@ void usePropertiesChanger(DBloodActor* sourceactor, int objType, int objIndex, D old = pWall->cstat; // set new cstat - if ((pSource->flags & kModernTypeFlag1)) pWall->cstat = pWall->cstat |= pXSource->data4; // relative + if ((pSource->flags & kModernTypeFlag1)) pWall->cstat |= pXSource->data4; // relative else pWall->cstat = pXSource->data4; // absolute // and hanlde exceptions @@ -5062,12 +5062,11 @@ bool aiFightMatesHaveSameTarget(DBloodActor* leaderactor, DBloodActor* targetact for (int i = bucketHead[rx]; i < bucketHead[rx + 1]; i++) { - if (rxBucket[i].type != OBJ_SPRITE) - continue; + if (rxBucket[i].type != OBJ_SPRITE) continue; - auto mate = rxBucket[i].actor; - if (!mate || !mate->hasX() || mate == leaderactor || !mate->IsDudeActor()) - continue; + auto mate = rxBucket[i].actor; + if (!mate || !mate->hasX() || mate == leaderactor || !mate->IsDudeActor()) + continue; if (mate->GetTarget() == targetactor && allow-- <= 0) return true; @@ -9059,8 +9058,8 @@ bool incDecGoalValueIsReached(DBloodActor* actor) { XSPRITE* pXSprite = &actor->x(); if (pXSprite->data3 != pXSprite->sysData1) return false; - char buffer[5]; - snprintf(buffer, 5, "%d", abs(pXSprite->data1)); + char buffer[7]; + snprintf(buffer, 7, "%d", abs(pXSprite->data1)); int len = int(strlen(buffer)); int rx = -1; diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 4c293f33d..037f0d10a 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -5099,7 +5099,7 @@ int dodge(DDukeActor* actor) int furthestangle(DDukeActor *actor, int angs) { auto s = actor->s; - int j, hitsect, hitwall, furthest_angle, angincs; + int j, hitsect, hitwall, furthest_angle = 0, angincs; int hx, hy, hz, d, greatestd; DDukeActor* dd; diff --git a/source/games/duke/src/actors_lava.cpp b/source/games/duke/src/actors_lava.cpp index 87cb045d4..81b713de2 100644 --- a/source/games/duke/src/actors_lava.cpp +++ b/source/games/duke/src/actors_lava.cpp @@ -345,6 +345,10 @@ void dojaildoor(void) auto wal = &wall[j]; switch (jaildoordir[i]) { + default: // make case of bad parameters well defined. + x = wal->x; + y = wal->y; + break; case 10: x = wal->x; y = wal->y + speed; @@ -427,23 +431,28 @@ void moveminecart(void) endwall = startwall + sectp->wallnum; for (j = startwall; j < endwall; j++) { + auto wal = &wall[j]; switch (minecartdir[i]) { + default: // make case of bad parameters well defined. + x = wal->x; + y = wal->y; + break; case 10: - x = wall[j].x; - y = wall[j].y + speed; + x = wal->x; + y = wal->y + speed; break; case 20: - x = wall[j].x - speed; - y = wall[j].y; + x = wal->x - speed; + y = wal->y; break; case 30: - x = wall[j].x; - y = wall[j].y - speed; + x = wal->x; + y = wal->y - speed; break; case 40: - x = wall[j].x + speed; - y = wall[j].y; + x = wal->x + speed; + y = wal->y; break; } dragpoint(j,x,y); @@ -561,7 +570,7 @@ void thunder(void) { struct player_struct* p; int r1, r2; - int startwall, endwall, i, j; + int startwall, endwall, i = 0, j; uint8_t shade; p = &ps[screenpeek]; diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index ae85185c4..9def10751 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -1572,7 +1572,7 @@ void movetransports_r(void) { uint8_t warpdir, warpspriteto; int k, p, sectlotag; - int ll2, ll, onfloorz; + int ll2 = 0, ll, onfloorz; Collision coll; //Transporters @@ -4104,14 +4104,13 @@ void fall_r(DDukeActor* ac, int g_p) void destroyit(DDukeActor *actor) { - int lotag, hitag; + int lotag = 0, hitag = 0; int wi, wj; int wallstart2, wallend2; int sectnum; int wallstart, wallend; DDukeActor* spr = nullptr; - hitag = 0; DukeSectIterator it1(actor->s->sectnum); while (auto a2 = it1.Next()) { diff --git a/source/games/duke/src/bowling.cpp b/source/games/duke/src/bowling.cpp index ac00bd71b..21c6e8e3f 100644 --- a/source/games/duke/src/bowling.cpp +++ b/source/games/duke/src/bowling.cpp @@ -164,7 +164,7 @@ int checkpins(int sect) void resetpins(int sect) { - int i, tag; + int i, tag = 0; int x, y; DukeSectIterator it(sect); while (auto a2 = it.Next()) diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 0795d46b0..05cd8cce3 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -2989,7 +2989,7 @@ int ParseState::parse(void) lMaxDistVar = *(insptr++); lVarID = *(insptr++); lMaxDist = GetGameVarID(lMaxDistVar, g_ac, g_p); - DDukeActor* lFound; + DDukeActor* lFound = nullptr; lDist = 32767; // big number DukeStatIterator it(STAT_ACTOR); diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 98fbb5c9d..eddc14f45 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -148,7 +148,7 @@ static void shootfireball(DDukeActor *actor, int p, int sx, int sy, int sz, int static void shootflamethrowerflame(DDukeActor* actor, int p, int sx, int sy, int sz, int sa) { auto s = actor->s; - int vel, zvel; + int vel, zvel = 0; if (s->extra >= 0) s->shade = -96; diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 0472f51f9..526aeee1e 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -209,7 +209,7 @@ static void shootweapon(DDukeActor* actor, int p, int sx, int sy, int sz, int sa { auto s = actor->s; int sect = s->sectnum; - int zvel; + int zvel = 0; int hitsect, hitwall; int hitx, hity, hitz; DDukeActor* hitsprt; diff --git a/source/games/duke/src/premap_r.cpp b/source/games/duke/src/premap_r.cpp index fe51152c1..961dae7eb 100644 --- a/source/games/duke/src/premap_r.cpp +++ b/source/games/duke/src/premap_r.cpp @@ -499,6 +499,7 @@ void prelevel_r(int g) { int ii; int childsectnum = -1; + dist = 0; DukeSectIterator it(i); while (auto act = it.Next()) { diff --git a/source/games/duke/src/spawn.cpp b/source/games/duke/src/spawn.cpp index 324cdefba..b3aeea4e3 100644 --- a/source/games/duke/src/spawn.cpp +++ b/source/games/duke/src/spawn.cpp @@ -624,7 +624,7 @@ void spawneffector(DDukeActor* actor) auto sectp = sp->sector(); int sect = sp->sectnum; auto t = actor->temp_data; - int startwall, endwall, x, y, d, s, clostest; + int startwall, endwall, x, y, d, s, clostest = 0; sp->yvel = sectp->extra; sp->cstat |= 32768; diff --git a/source/games/exhumed/src/move.cpp b/source/games/exhumed/src/move.cpp index eb83372d0..5177de159 100644 --- a/source/games/exhumed/src/move.cpp +++ b/source/games/exhumed/src/move.cpp @@ -288,7 +288,7 @@ int BelowNear(DExhumedActor* pActor, int x, int y, int walldist, int nSector) if (GlobalSectorList.Size() > nearstart) { - short edx; + int edx = 0; for (unsigned i = nearstart; i < GlobalSectorList.Size(); i++) { @@ -697,8 +697,8 @@ int GetAngleToSprite(DExhumedActor* a1, DExhumedActor* a2) if (!a1 || !a2) return -1; - auto pSprite1 = &a1->s(); - auto pSprite2 = &a2->s(); + auto pSprite1 = &a1->s(); + auto pSprite2 = &a2->s(); return GetMyAngle(pSprite2->x - pSprite1->x, pSprite2->y - pSprite1->y); } @@ -708,8 +708,8 @@ int PlotCourseToSprite(DExhumedActor* pActor1, DExhumedActor* pActor2) if (pActor1 == nullptr || pActor2 == nullptr) return -1; - auto pSprite1 = &pActor1->s(); - auto pSprite2 = &pActor2->s(); + auto pSprite1 = &pActor1->s(); + auto pSprite2 = &pActor2->s(); int x = pSprite2->x - pSprite1->x; int y = pSprite2->y - pSprite1->y; diff --git a/source/games/sw/src/cheats.cpp b/source/games/sw/src/cheats.cpp index d26c43721..ec4035484 100644 --- a/source/games/sw/src/cheats.cpp +++ b/source/games/sw/src/cheats.cpp @@ -160,7 +160,7 @@ bool WarpCheat(cheatseq_t* c) if (TEST(pp->Flags, PF_DEAD)) return true; - DeferredStartGame(maprec, g_nextskill); + DeferredStartGame(maprec, g_nextskill); return true; } diff --git a/source/games/sw/src/game.cpp b/source/games/sw/src/game.cpp index 01317a4ac..d5f3bcd19 100644 --- a/source/games/sw/src/game.cpp +++ b/source/games/sw/src/game.cpp @@ -219,7 +219,7 @@ void GameInterface::app_init() for (int i = 0; i < MAX_SW_PLAYERS; i++) INITLIST(&Player[i].PanelSpriteList); - LoadCustomInfoFromScript("engine/swcustom.txt"); // load the internal definitions. These also apply to the shareware version. + LoadCustomInfoFromScript("engine/swcustom.txt"); // load the internal definitions. These also apply to the shareware version. if (!SW_SHAREWARE) LoadCustomInfoFromScript("swcustom.txt"); // Load user customisation information diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 08d2a313e..19b297f50 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -854,6 +854,14 @@ struct PLAYERstruct PANEL_SPRITEp Next, Prev; } PanelSpriteList; + // hack stuff to get a working pointer to this list element without running into type punning warnings with GCC. + // The list uses itself as sentinel element despite the type mismatch. + PANEL_SPRITEp GetPanelSpriteList() + { + void* p = &PanelSpriteList; + return reinterpret_cast(p); + } + // Key stuff unsigned char HasKey[8]; diff --git a/source/games/sw/src/interpso.cpp b/source/games/sw/src/interpso.cpp index eac8e1215..95fafe0ff 100644 --- a/source/games/sw/src/interpso.cpp +++ b/source/games/sw/src/interpso.cpp @@ -97,12 +97,15 @@ static int &getvalue(so_interp::interp_data& element, bool write) case soi_sprx: if (element.actorofang) return element.actorofang->s().x; + break; case soi_spry: if (element.actorofang) return element.actorofang->s().y; + break; case soi_sprz: if (element.actorofang) return element.actorofang->s().z; + break; default: break; } diff --git a/source/games/sw/src/lists.h b/source/games/sw/src/lists.h index bb4971395..05130fd46 100644 --- a/source/games/sw/src/lists.h +++ b/source/games/sw/src/lists.h @@ -39,22 +39,21 @@ typedef struct List *Prev; } LISTHEAD, *LIST; -#define FIRST(list) (list->Next) -#define LAST(list) (list->Prev) +inline void INITLIST(void* listp) +{ + LIST list = (LIST)listp; + list->Prev = list->Next = list; +} - -#define INITLIST(list) ( ((LIST) list)->Prev = ((LIST) list)->Next = (LIST) list) - - -#define INSERT(list, nodep) ( ((LIST) nodep)->Prev = (LIST) list, \ - ((LIST) nodep)->Next = ((LIST) list)->Next, \ - ((LIST) list)->Next = (LIST) nodep, \ - ((LIST) nodep)->Next->Prev = (LIST) nodep) - -#define INSERT_TAIL(list, nodep) ( ((LIST) nodep)->Next = (LIST) list, \ - ((LIST) nodep)->Prev = ((LIST) list)->Prev, \ - ((LIST) list)->Prev = (LIST) nodep, \ - ((LIST) nodep)->Prev->Next = (LIST) nodep) +inline void INSERT(void* listp, void* nodepp) +{ + LIST list = (LIST)listp; + LIST nodep = (LIST)nodepp; + nodep->Prev = list; + nodep->Next = list->Next; + list->Next = nodep; + nodep->Next->Prev = nodep; +} inline void REMOVE(PANEL_SPRITEp nodep) { @@ -62,11 +61,11 @@ inline void REMOVE(PANEL_SPRITEp nodep) nodep->Next->Prev = nodep->Prev; } -#define TRAVERSE(l, o, n) ASSERT(((LIST)l)->Next && ((LIST)l)->Prev); for (o = (decltype(o))(((LIST)l)->Next); \ - n = o->Next, (LIST) o != (LIST) l; \ - o = n) - -#define EMPTY(list) (((LIST) list)->Next == (LIST) list) +inline bool EMPTY(void* listp) +{ + LIST list = (LIST)listp; + return list->Next == list; +} END_SW_NS diff --git a/source/games/sw/src/panel.cpp b/source/games/sw/src/panel.cpp index 8b9a492c8..d29cedb05 100644 --- a/source/games/sw/src/panel.cpp +++ b/source/games/sw/src/panel.cpp @@ -116,9 +116,10 @@ void pNullAnimator(PANEL_SPRITEp) PANEL_SPRITEp pFindMatchingSprite(PLAYERp pp, int x, int y, short pri) { - PANEL_SPRITEp psp=nullptr, next; + PANEL_SPRITEp next; - TRAVERSE(&pp->PanelSpriteList, psp, next) + auto list = pp->GetPanelSpriteList(); + for (auto psp = list->Next; next = psp->Next, psp != list; psp = next) { // early out if (psp->priority > pri) @@ -135,9 +136,10 @@ PANEL_SPRITEp pFindMatchingSprite(PLAYERp pp, int x, int y, short pri) PANEL_SPRITEp pFindMatchingSpriteID(PLAYERp pp, short id, int x, int y, short pri) { - PANEL_SPRITEp psp=nullptr, next; + PANEL_SPRITEp next; - TRAVERSE(&pp->PanelSpriteList, psp, next) + auto list = pp->GetPanelSpriteList(); + for (auto psp = list->Next; next = psp->Next, psp != list; psp = next) { // early out if (psp->priority > pri) @@ -154,11 +156,12 @@ PANEL_SPRITEp pFindMatchingSpriteID(PLAYERp pp, short id, int x, int y, short pr bool pKillScreenSpiteIDs(PLAYERp pp, short id) { - PANEL_SPRITEp psp=nullptr, next; + PANEL_SPRITEp next; bool found = false; // Kill ALL sprites with the correct id - TRAVERSE(&pp->PanelSpriteList, psp, next) + auto list = pp->GetPanelSpriteList(); + for (auto psp = list->Next; next = psp->Next, psp != list; psp = next) { if (psp->ID == id) { @@ -327,7 +330,6 @@ void PlayerUpdateHealth(PLAYERp pp, short value) void PlayerUpdateAmmo(PLAYERp pp, short UpdateWeaponNum, short value) { - USERp u = pp->Actor()->u(); short x,y; short WeaponNum; @@ -924,7 +926,8 @@ void RetractCurWpn(PLAYERp pp) else { // check for any outstanding siblings that need to go away also - TRAVERSE(&pp->PanelSpriteList, cur, nxt) + auto list = pp->GetPanelSpriteList(); + for (auto cur = list->Next; nxt = cur->Next, cur != list; cur = nxt) { if (cur->sibling && cur->sibling == pp->CurWpn) { @@ -6410,7 +6413,8 @@ InsertPanelSprite(PLAYERp pp, PANEL_SPRITEp psp) } // search for first pri in list thats less than the new pri - TRAVERSE(&pp->PanelSpriteList, cur, nxt) + auto list = pp->GetPanelSpriteList(); + for (auto cur = list->Next; nxt = cur->Next, cur != list; cur = nxt) { // if the next pointer is the end of the list, insert it if ((LIST) cur->Next == (LIST) &pp->PanelSpriteList) @@ -6568,7 +6572,7 @@ void pDisplaySprites(PLAYERp pp, double smoothratio) { USERp u = pp->Actor()->u(); - PANEL_SPRITEp psp=nullptr, next=nullptr; + PANEL_SPRITEp next=nullptr; short shade, picnum, overlay_shade = 0; double x, y; unsigned i; @@ -6580,7 +6584,8 @@ pDisplaySprites(PLAYERp pp, double smoothratio) double const look_anghalf = pp->angle.look_anghalf(smoothratio); double const looking_arc = pp->angle.looking_arc(smoothratio); - TRAVERSE(&pp->PanelSpriteList, psp, next) + auto list = pp->GetPanelSpriteList(); + for (auto psp = list->Next; next = psp->Next, psp != list; psp = next) { ang = psp->rotate_ang; shade = 0; @@ -6856,9 +6861,10 @@ pDisplaySprites(PLAYERp pp, double smoothratio) void pSpriteControl(PLAYERp pp) { - PANEL_SPRITEp psp=nullptr, next=nullptr; + PANEL_SPRITEp next=nullptr; - TRAVERSE(&pp->PanelSpriteList, psp, next) + auto list = pp->GetPanelSpriteList(); + for (auto psp = list->Next; next = psp->Next, psp != list; psp = next) { // reminder - if these give an assertion look for pKillSprites // somewhere else other than by themselves diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index 0319ac290..566f570f0 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -2192,7 +2192,7 @@ OperateContinuousTrigger(PLAYERp pp) if (pp->cursectnum < 0) return; - switch (sector[pp->cursectnum].lotag) + switch (sector[pp->cursectnum].lotag) { case TAG_TRIGGER_MISSILE_TRAP: { diff --git a/source/games/sw/src/sprite.cpp b/source/games/sw/src/sprite.cpp index afabc277b..8af579946 100644 --- a/source/games/sw/src/sprite.cpp +++ b/source/games/sw/src/sprite.cpp @@ -1861,11 +1861,11 @@ SpriteSetup(void) PicAnimOff(PLAYER_NINJA_RUN_R0); // Clear Sprite Extension structure - memset(&SectUser[0], 0, sizeof(SectUser)); // Clear all extra bits - they are set by sprites for (i = 0; i < numsectors; i++) { + SectUser[i].Clear(); sector[i].extra = 0; }