NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/43860: Undefined behavior in src/games/monop/cards.c



>Number:         43860
>Category:       bin
>Synopsis:       Undefined behavior in src/games/monop/cards.c
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 09 20:40:01 +0000 2010
>Originator:     Chris Spiegel
>Release:        5.0.2
>Organization:
>Environment:
N/A: discovered while porting to another platform.
>Description:
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.
>How-To-Repeat:

>Fix:
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.



Home | Main Index | Thread Index | Old Index