Skip to content

Commit 4f46c20

Browse files
committed
Add parentheses around macro arguments
This fixes actual problem reported by clang: in client.cpp, maplist(..., i!=0); expands to mapshrink(!i!=0, ...) which is interpreted as (!i)!=0 instead of !(i!=0). Nice example why macros are evil. By happy coincidence, this still works correctly, but fix this nevertheless and add some more parens in other expressions just for the case.
1 parent 0e67905 commit 4f46c20

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/game/gamemode.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ extern mutstypes mutstype[];
285285
{ \
286286
mapshrink(m_multi(b, c) && (m_capture(b) || (m_bomber(b) && !m_gsp1(b, c))), a, G(multimaps), false) \
287287
mapshrink(m_duel(b, c), a, G(duelmaps), false) \
288-
if(d > 0 && e >= 2 && m_fight(b) && !m_duel(b, c)) \
288+
if((d) > 0 && (e) >= 2 && m_fight(b) && !m_duel(b, c)) \
289289
{ \
290-
mapshrink(G(smallmapmax) && d <= G(smallmapmax), a, G(smallmaps), false) \
291-
else mapshrink(G(mediummapmax) && d <= G(mediummapmax), a, G(mediummaps), false) \
292-
else mapshrink(G(mediummapmax) && d > G(mediummapmax), a, G(largemaps), false) \
290+
mapshrink(G(smallmapmax) && (d) <= G(smallmapmax), a, G(smallmaps), false) \
291+
else mapshrink(G(mediummapmax) && (d) <= G(mediummapmax), a, G(mediummaps), false) \
292+
else mapshrink(G(mediummapmax) && (d) > G(mediummapmax), a, G(largemaps), false) \
293293
} \
294-
mapshrink(!f, a, G(previousmaps), true) \
294+
mapshrink(!(f), a, G(previousmaps), true) \
295295
}
296296
#define maplist(a,b,c,d,e,f) \
297297
{ \
@@ -302,7 +302,7 @@ extern mutstypes mutstype[];
302302
else if(m_fight(b)) a = newstring(G(mainmaps)); \
303303
else a = newstring(G(allowmaps)); \
304304
if(e) mapcull(a, b, c, d, e, f) \
305-
else mapshrink(!f, a, G(previousmaps), true) \
305+
else mapshrink(!(f), a, G(previousmaps), true) \
306306
}
307307
#ifdef GAMESERVER
308308
SVAR(0, gamestatename, "waiting voting intermission playing overtime");

0 commit comments

Comments
 (0)