Quantcast
Channel: LabWindows/CVI topics
Viewing all articles
Browse latest Browse all 5339

ListFindItem with StartingPosition out of range: BUG

$
0
0

Hello,

 

The index returned by ListFindItem is WRONG when:

  • StartingPosition  = 0 ( this is a wrong value: StartingPosition must be >=1) .
  • The searched value equal to the LAST item inserted in the List:

The code example below shows the bug in the TEST_D:

 

int main (int argc, char *argv[])
{
	ssize_t 	startingPosition = 0;
	size_t 		index = 0;
	int 		val = 0;

	ListType myList = NULL;
	
	myList = ListCreate (sizeof(int));
	
	val = 1;
	ListInsertItem (myList, &val, END_OF_LIST);
	val = 2;
	ListInsertItem (myList, &val, END_OF_LIST);
	val = 3;
	ListInsertItem (myList, &val, END_OF_LIST);
	// TEST_A: OK
	startingPosition = 1;
	val = 1;
	index = ListFindItem (myList, &val, startingPosition, IntCompare);
	// index = 1 --> OK

	// TEST_B: OK
	startingPosition = 10; // WRONG value: startingPosition is over the number of items.
	val = 1;   
	index = ListFindItem (myList, &val, startingPosition, IntCompare);
	// index = 0 --> OK because startingPosition is out of range (>3)
	// TEST_C: OK
	startingPosition = 0; // WRONG value: startingPosition must be >= 1
	val = 1;
	index = ListFindItem (myList, &val, startingPosition, IntCompare);
	// index = 0 --> OK because startingPosition is out of range (<1)  
	// TEST_D: NOT OK
	startingPosition = 0; // WRONG value: startingPosition must be >= 1
	val = 3;   // value of the LAST ITEM inserted in the List
	index = ListFindItem (myList, &val, startingPosition, IntCompare);
	// index = 3 --> NOT OK: the behaviour is different compare to TEST_C. 
	// In this case, ListFindItem must return 0 (NOT 3) because startingPosition is out of range (<1).
	// If you look for another item (not the last: val=1 ou val=2) ListFinfItem returns 0 --> OK
	return 0;
}

 

 

 


Viewing all articles
Browse latest Browse all 5339

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>