:: [intv] Biggest bug that I ever found ::
HOME


[Date Prev][Date Next][Date Index]

[intv] Biggest bug that I ever found


Here is a small piece of program that has a bug and was impossible to find where the bug is.

Basically, i am using a link list to insert, access and remove some values. The insert method (op_prg_list_insert) adds a pointer to the element in the linkled list.
I used the below for-lopp to add integers from 0 to 9.
for (i = 0; i < 10; i++){
op_prg_list_insert (free_sar_contexts,&i, OPC_LISTPOS_TAIL);
}


Note that I made a mistake above. The insert statement will insert the address of variable "i" 10 times into the link list. That was the bug. I was supposed to insert a newly allocated element each time. However i was not able to find it becuase of the following statements.


Here i was trying to see if the link list contains elements 0-9 and it was printing properly/


printf("Before *****\n");
for (i = 0; i < op_prg_list_size(free_sar_contexts); i++){
b = op_prg_list_access (free_sar_contexts, OPC_LISTPOS_TAIL);
printf("free %d\n",*b );
}
In the above, the access function returns the pointer to variable i and the printf statement just prints i.
So i was getting an output showing that 0-9 were actually getting added to the list, while the truth was i was only printing the variable i.




Now I remove the elements from the list.
printf("Removing.........\n");
b = (int *)op_prg_list_remove (free_sar_contexts, OPC_LISTPOS_TAIL);	
printf("Removed %d\n",*b );


b = (int *)op_prg_list_remove (free_sar_contexts, OPC_LISTPOS_TAIL); printf("Removed %d\n",*b );

I was getiin an o/p like element "10" was removed. This confused me as I had not inserted 10. However I later realized the i was 10.




Again when i printed out the list it was printing 0-7 which I expected. So i had no idea where the error was., printf("After *****\n");

for (i = 0; i < op_prg_list_size(free_sar_contexts); i++){
	b = op_prg_list_access (free_sar_contexts, OPC_LISTPOS_TAIL);	
	printf("free %d\n",*b );
}

shank


Comments and corrections are appreciated and can be sent to papers@mia.ece.uic.edu. Click here for ©opyright information.