[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
bin/43860: Undefined behavior in src/games/monop/cards.c
>Synopsis: Undefined behavior in src/games/monop/cards.c
>Arrival-Date: Thu Sep 09 20:40:01 +0000 2010
>Originator: Chris Spiegel
N/A: discovered while porting to another platform.
Line 250 of src/games/monop/cards.c is:
dp->top_card = ++(dp->top_card) % dp->num_cards;
This violates §6.5p2 of C99 ("Between the previous and next sequence point an
object shall have its stored value modified at most once by the evaluation of
an expression."). C89/C90 have identical wording.
I presume the following implements the expected behavior:
dp->top_card = (dp->top_card + 1) % dp->num_cards;
That is, change the preincrement to a simple "x+1" construct.
Main Index |
Thread Index |