[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdegames/kpat/patsolve
From: Stephan Kulow <coolo () kde ! org>
Date: 2011-11-14 12:44:09
Message-ID: 20111114124409.21823AC88B () svn ! kde ! org
[Download RAW message or body]
SVN commit 1264171 by coolo:
don't overfill the possible array
BUG: 283191
M +11 -5 gypsysolver.cpp
M +2 -0 patsolve.cpp
--- trunk/KDE/kdegames/kpat/patsolve/gypsysolver.cpp #1264170:1264171
@@ -20,6 +20,7 @@
#include "../gypsy.h"
#include <KDebug>
+#include <assert.h>
#define PRINT 0
@@ -362,14 +363,14 @@
mp->to = j;
mp->totype = W_Type;
mp->turn_index = -1;
- if ( Wlen[i] > l+1 && DOWN( W[i][Wlen[i]-l-2] ) )
- mp->turn_index = 1;
- if ( mp->turn_index > 0 )
- mp->pri = params[2];
- else
mp->pri = params[3];
if (Wlen[i] >= 2+l) {
+ assert(Wlen[i]-2-l >= 0);
card_t card2 = W[i][Wlen[i]-2-l];
+ if (DOWN(card2)) {
+ mp->turn_index = 1;
+ mp->pri = params[2];
+ }
if ( Wlen[i] >= l+2 && RANK( card ) == RANK( card2 ) - 1 &&
COLOR( card ) != COLOR( card2 ) && !DOWN( card2 ) )
{
@@ -390,12 +391,16 @@
mp->pri = ( int )qMin( qreal( 127. ), params[1] + qreal( l ) * params[5] / 10 );
}
}
+
n++;
mp++;
+ // leave one for redeal
+ if (n >= MAXMOVES - 2) goto redeal;
}
}
}
+redeal:
if ( Wlen[deck] )
{
/* check for redeal */
@@ -409,6 +414,7 @@
mp++;
}
+ assert(n < MAXMOVES);
return n;
}
--- trunk/KDE/kdegames/kpat/patsolve/patsolve.cpp #1264170:1264171
@@ -29,6 +29,7 @@
#include <cstdarg>
#include <cstdlib>
#include <cstring>
+#include <cassert>
#include <sys/types.h>
@@ -105,6 +106,7 @@
/* Fill in the Possible array. */
alln = get_possible_moves(&a, &numout);
+ assert(alln < MAXMOVES);
if (alln == 0) {
if ( isWon() ) {
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic