/usr/include/poker-eval/enumerate.h incorrectly assumes sizeof(int)==sizeof(int*)
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
poker-eval (Ubuntu) |
Expired
|
Low
|
Unassigned |
Bug Description
The offending line is line 624:
_curElem = (int **) malloc(num_sets * sizeof(int)); \
It should read:
_curElem = (int **) malloc(num_sets * sizeof(int*)); \
because the array being allocated is an array of int*, as shown by the cast, not an array of int. On an x86 system, this is probably fine, but on amd64, sizeof(int) != sizeof(int*).
This causes a crash in a program I wrote using python-pypoker-eval to evaluate pre-flop odds in Texas Hold'em, but only when more than 2 hands are passed to it.
The program (preflop_
#!/usr/bin/env python
import itertools
import sys
import pokereval
def matchup(hands):
pok = pokereval.
answer = pok.poker_
samples = float(answer[
for hand, results in zip(hands, answer['eval']):
win_pct = results['scoop'] / samples * 100
tie_pct = results['tiehi'] / samples * 100
print '%s: %f%% to win, %f%% to tie' % (hand, win_pct, tie_pct)
def grouper(n, iterable, fillvalue=None):
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
args = [iter(iterable)] * n
return itertools.
def main(argv):
hands = []
for item in argv:
hand = list(''.join(x) for x in grouper(2, item))
if len(hand) != 2:
raise Exception('hands must contain two cards of 2 chars each!')
hands.
matchup(hands)
if __name__ == '__main__':
main(
To reproduce the crash, on an amd64 Ubuntu 10.4 LTS system:
python preflop_matchup.py 9h9s adjd jc7c
Correcting the offending line solves the problem. This may already be fixed upstream, as the Ubuntu package is 1 revision out of date.
tags: | added: patch |
checking latest release of poker-eval (137.0) that line now is replaced by: " _curElem = (int **) malloc(num_sets * sizeof(intptr_t)); \ ", , please could you check if this issue is still occuring under latest release included in Maverick (or use that code just for testing under Lucid)? Thanks.