codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
void deduct_gold_from_player_for_gold_auction(int64 &playersGold, int numberOfStacks) { const int GOLD_PER_STACK = 10000000; //imagine numberOfStacks * GOLD_PER_STACK is 6 billion //goldToRemove is 32 bits and will not be enough to //hold the gold to deduct, it will overflow and flip //to a value lesser than 2 billion. int goldToRemove = numberOfStacks * GOLD_PER_STACK; playersGold -= goldToRemove; //only < 2 billion deducted! } // void refund_gold_to_player ( ... ) { //here the right math would give back the full 6 billion! }
Private
[
?
]
Run code
Submit