This is the mail archive of the xconq7@sources.redhat.com mailing list for the Xconq project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Unstable pre-release version of enhanced ai_plan_research


Lincoln Peters wrote:
	

uWeight = malloc( 2 * numAdvances );


I would suggest:
uweight = (int *)xmalloc(num_advances * sizeof(int));
Xconq's 'xmalloc' checks to see if the 'malloc' succeeded. If it failed, then 'run_error' is invoked. 'xmalloc' also scrubs the allocated memory to be 0 everywhere.
Furthermore, the problem could be here, because you allocate an array of 2-byte slots, but you declared the storage type as an 'int' which is likely 4 bytes on your system. So, if 'numAdvances' is 4, then you allocate 8 bytes, but when you do 'uWeight[3]', you are accessing the 12th through 15th bytes! Ooops.


	for_all_advance_types(count1) {
		uWeight[count1] = 0;

The problem could be here. Your 'count1' variable iterates from 0 to 'numatypes', but the array is only allocated with 'numAdvances' positions. 'numAdvances' <= 'numatypes'. You have to worry about the < case, because that is a potential source of your crash.


				} else if ( ua_multiply_production( count3, count1 ) < 1 ) {
					uWeight[count2] -= 1.0 / ua_multiply_production( count3, count1 );
				}

The above snippet is a potential divide by zero case. Also, the righthand side evaluates to a floating point value, whereas the storage on the lefthand side is of an integer type. Furthermore, a factor of 1.0 is internally 100 in Xconq, so to get a reciprocal, you can do:
uweight[count2] -= 10000 / ua_multiply_production(count3, count1);

Eric



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]