/usr/include/poker-eval/enumerate.h incorrectly assumes sizeof(int)==sizeof(int*)

Bug #605737 reported by Scott Wolchok
10
This bug affects 1 person
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_matchup.py):

#!/usr/bin/env python

import itertools
import sys

import pokereval

def matchup(hands):
  pok = pokereval.PokerEval()
  answer = pok.poker_eval(game='holdem',
                          pockets=hands,
                          board=['__', '__', '__', '__', '__'])
  samples = float(answer['info'][0])
  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.izip_longest(fillvalue=fillvalue, *args)

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.append(hand)
  matchup(hands)

if __name__ == '__main__':
  main(sys.argv[1:])

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: patch
Revision history for this message
Scott Wolchok (scott-wolchok) wrote :
tags: added: patch
Revision history for this message
Victor Vargas (kamus) wrote :

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.

Changed in poker-eval (Ubuntu):
importance: Undecided → Low
status: New → Incomplete
Revision history for this message
Scott Wolchok (scott-wolchok) wrote :

Yes, s/sizeof(int*)/sizeof(intptr_t)/ in the patch seems to work just as well. I'd argue it's bad style, but that's a different debate.

Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for poker-eval (Ubuntu) because there has been no activity for 60 days.]

Changed in poker-eval (Ubuntu):
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.