From 9d63bcaed353f093ad6297774e08c979a0135776 Mon Sep 17 00:00:00 2001 From: LegendaryGuard Date: Sat, 5 Aug 2023 11:46:58 +0200 Subject: [PATCH] Wrap all status and bitflag checks with parentesis to avoid possible obscure bugs --- qcsrc/common/minigames/minigame/pong.qc | 2 +- qcsrc/common/minigames/minigame/pp.qc | 2 +- qcsrc/common/weapons/weapon/porto.qc | 2 +- qcsrc/menu/xonotic/dialog_welcome.qc | 2 +- qcsrc/menu/xonotic/maplist.qc | 2 +- qcsrc/server/bot/default/havocbot/havocbot.qc | 4 ++-- qcsrc/server/bot/default/navigation.qc | 2 +- qcsrc/server/bot/default/scripting.qc | 6 +++--- qcsrc/server/bot/default/waypoints.qc | 4 ++-- qcsrc/server/items/items.qc | 2 +- qcsrc/server/items/spawning.qh | 2 +- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/qcsrc/common/minigames/minigame/pong.qc b/qcsrc/common/minigames/minigame/pong.qc index 412273d90..698ccfb55 100644 --- a/qcsrc/common/minigames/minigame/pong.qc +++ b/qcsrc/common/minigames/minigame/pong.qc @@ -703,7 +703,7 @@ int pong_client_event(entity minigame, string event, ...) case "menu_click": { string cmd = ...(0,string); - if( cmd == "pong_throw" && minigame.minigame_flags & PONG_STATUS_WAIT ) + if( cmd == "pong_throw" && ( minigame.minigame_flags & PONG_STATUS_WAIT ) ) { minigame_cmd("throw"); } diff --git a/qcsrc/common/minigames/minigame/pp.qc b/qcsrc/common/minigames/minigame/pp.qc index 1c755b640..9a7e54234 100644 --- a/qcsrc/common/minigames/minigame/pp.qc +++ b/qcsrc/common/minigames/minigame/pp.qc @@ -452,7 +452,7 @@ string pp_turn_to_string(int turnflags) if ( turnflags & PP_TURN_WIN ) { // translator-friendly messages composed of 2 existing messages - if ( (turnflags&PP_TURN_TEAM) != minigame_self.team ) + if ( (turnflags & PP_TURN_TEAM) != minigame_self.team ) return strcat(_("You lost the game!"), "\n", _("Select \"^1Next Match^7\" on the menu for a rematch!")); return strcat(_("You win!"), "\n", _("Select \"^1Next Match^7\" on the menu to start a new match!")); } diff --git a/qcsrc/common/weapons/weapon/porto.qc b/qcsrc/common/weapons/weapon/porto.qc index 7ee416215..9a1f7b26b 100644 --- a/qcsrc/common/weapons/weapon/porto.qc +++ b/qcsrc/common/weapons/weapon/porto.qc @@ -171,7 +171,7 @@ void W_Porto_Touch(entity this, entity toucher) traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * PL_MIN_CONST.z, MOVE_WORLDONLY, this); if(trace_fraction >= 1) return; - if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP) + if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) || (trace_dphitcontents & DPCONTENTS_PLAYERCLIP)) return; if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) return; diff --git a/qcsrc/menu/xonotic/dialog_welcome.qc b/qcsrc/menu/xonotic/dialog_welcome.qc index 1651af5e6..addafe6c0 100644 --- a/qcsrc/menu/xonotic/dialog_welcome.qc +++ b/qcsrc/menu/xonotic/dialog_welcome.qc @@ -93,7 +93,7 @@ void XonoticWelcomeDialog_draw(entity me) if (!(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))) me.close(me); - if(me.serverinfo_MOTD == "" && gamestatus & (GAME_CONNECTED | GAME_ISSERVER)) + if(me.serverinfo_MOTD == "" && (gamestatus & (GAME_CONNECTED | GAME_ISSERVER))) { // if serverinfo_MOTD is empty while connected it means we are connected to an old server // in this case show the csqc welcome message and instantly close the dialog diff --git a/qcsrc/menu/xonotic/maplist.qc b/qcsrc/menu/xonotic/maplist.qc index 1fa065874..81bf34e52 100644 --- a/qcsrc/menu/xonotic/maplist.qc +++ b/qcsrc/menu/xonotic/maplist.qc @@ -80,7 +80,7 @@ void XonoticMapList_draw(entity me) { if(me.startButton) me.startButton.disabled = ((me.selectedItem < 0) || (me.selectedItem >= me.nItems) - || (gamestatus & (GAME_ISSERVER | GAME_CONNECTED) && cvar("g_campaign"))); + || ((gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) && cvar("g_campaign"))); SUPER(XonoticMapList).draw(me); } diff --git a/qcsrc/server/bot/default/havocbot/havocbot.qc b/qcsrc/server/bot/default/havocbot/havocbot.qc index c8855660a..e7bf9e5a3 100644 --- a/qcsrc/server/bot/default/havocbot/havocbot.qc +++ b/qcsrc/server/bot/default/havocbot/havocbot.qc @@ -625,7 +625,7 @@ void havocbot_movetogoal(entity this) if (this.items & IT_JETPACK) action_for_trigger_hurt = 1; else if (!this.jumppadcount && !waypoint_is_hardwiredlink(this.goalcurrent_prev, this.goalcurrent) - && !(this.goalcurrent_prev && this.goalcurrent_prev.wpflags & WAYPOINTFLAG_JUMP) + && !(this.goalcurrent_prev && (this.goalcurrent_prev.wpflags & WAYPOINTFLAG_JUMP)) && GetResource(this, RES_HEALTH) + GetResource(this, RES_ARMOR) > ROCKETJUMP_DAMAGE()) { action_for_trigger_hurt = 2; @@ -883,7 +883,7 @@ void havocbot_movetogoal(entity this) bool bunnyhop_forbidden = false; vector destorg = get_closer_dest(this.goalcurrent, this.origin); - if (this.jumppadcount && this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT) + if (this.jumppadcount && (this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)) { // if bot used the jumppad, push towards jumppad origin until jumppad waypoint gets removed destorg = this.goalcurrent.origin; diff --git a/qcsrc/server/bot/default/navigation.qc b/qcsrc/server/bot/default/navigation.qc index 87bb5c0cd..98069e0ab 100644 --- a/qcsrc/server/bot/default/navigation.qc +++ b/qcsrc/server/bot/default/navigation.qc @@ -1738,7 +1738,7 @@ int navigation_poptouchedgoals(entity this) navigation_poproute(this); ++removed_goals; - if(this.goalcurrent && this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT) + if(this.goalcurrent && (this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)) return removed_goals; } } diff --git a/qcsrc/server/bot/default/scripting.qc b/qcsrc/server/bot/default/scripting.qc index 4ad6246e6..960ac2162 100644 --- a/qcsrc/server/bot/default/scripting.qc +++ b/qcsrc/server/bot/default/scripting.qc @@ -1212,13 +1212,13 @@ float bot_execute_commands_once(entity this) ispressingkey = boolean(bot_presskeys(this)); // Handle conditions - if (!(bot_cmd.bot_cmd_type==BOT_CMD_FI||bot_cmd.bot_cmd_type==BOT_CMD_ELSE)) - if((this.bot_cmd_condition_status & CMD_CONDITION_true) && this.bot_cmd_condition_status & CMD_CONDITION_false_BLOCK) + if (!(bot_cmd.bot_cmd_type == BOT_CMD_FI || bot_cmd.bot_cmd_type == BOT_CMD_ELSE)) + if((this.bot_cmd_condition_status & CMD_CONDITION_true) && (this.bot_cmd_condition_status & CMD_CONDITION_false_BLOCK)) { bot_command_executed(this, true); return -1; } - else if((this.bot_cmd_condition_status & CMD_CONDITION_false) && this.bot_cmd_condition_status & CMD_CONDITION_true_BLOCK) + else if((this.bot_cmd_condition_status & CMD_CONDITION_false) && (this.bot_cmd_condition_status & CMD_CONDITION_true_BLOCK)) { bot_command_executed(this, true); return -1; diff --git a/qcsrc/server/bot/default/waypoints.qc b/qcsrc/server/bot/default/waypoints.qc index 88ea34de2..d6bc1e670 100644 --- a/qcsrc/server/bot/default/waypoints.qc +++ b/qcsrc/server/bot/default/waypoints.qc @@ -1563,9 +1563,9 @@ void waypoint_load_hardwiredlinks() { waypoint_addlink(wp_from, wp_to); waypoint_mark_hardwiredlink(wp_from, wp_to); - } else if (wp_from.wpflags & WPFLAGMASK_NORELINK + } else if ((wp_from.wpflags & WPFLAGMASK_NORELINK) && ((wp_from.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT)) - || (wp_from.wpisbox && wp_from.wpflags & WAYPOINTFLAG_TELEPORT))) + || (wp_from.wpisbox && (wp_from.wpflags & WAYPOINTFLAG_TELEPORT)))) { waypoint_addlink(wp_from, wp_to); } diff --git a/qcsrc/server/items/items.qc b/qcsrc/server/items/items.qc index fe677d7f1..ed8ba9a52 100644 --- a/qcsrc/server/items/items.qc +++ b/qcsrc/server/items/items.qc @@ -578,7 +578,7 @@ bool Item_GiveTo(entity item, entity player) } int its; - if((its = (item.items - (item.items & player.items)) & IT_PICKUPMASK)) + if((its = (item.items - ((item.items & player.items)) & IT_PICKUPMASK))) { pickedup = true; player.items |= its; diff --git a/qcsrc/server/items/spawning.qh b/qcsrc/server/items/spawning.qh index 7b19292c6..223eb57fb 100644 --- a/qcsrc/server/items/spawning.qh +++ b/qcsrc/server/items/spawning.qh @@ -45,7 +45,7 @@ bool Item_Initialise(entity item); /// \param[in] item Item to check. /// \return True if item should keep its position or false if it should be /// dropped to the ground. -#define ITEM_SHOULD_KEEP_POSITION(item) (item.noalign || item.spawnflags & 1) +#define ITEM_SHOULD_KEEP_POSITION(item) (item.noalign || (item.spawnflags & 1)) /// \brief Returns whether the item is expiring (i.e. its strength, shield and /// superweapon timers expire while it is on the ground). -- 2.39.2