This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libobjc/38881] New: Two problem in objc-list.h in list_remove_elem
- From: "bartosz dot kuzma at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Jan 2009 20:08:12 -0000
- Subject: [Bug libobjc/38881] New: Two problem in objc-list.h in list_remove_elem
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
There are two problems with list_remove_elem function in objc/objc-list.h file:
- function dumps core when remove first element of the list,
- if element is in the list more than once and copy of the element are one by
one they do not be removed all.
struct objc_list *list = 0;
int elem_1 = 1;
int elem_2 = 2;
int elem_3 = 3;
list = list_cons((void *)&elem_1, list);
list = list_cons((void *)&elem_2, list);
list = list_cons((void *)&elem_2, list);
list = list_cons((void *)&elem_2, list);
list = list_cons((void *)&elem_3, list);
list_remove_elem(&list, (void *)&elem_2); // Remove only 2 elem_2!
list_remove_elem(&list, (void *)&elem_1); // Core dumps!
After list_remove_head should have not changed pointer to tail. The following
patch repair both problems.
--- /usr/include/objc/objc-list.h 2006-04-20 11:55:22.000000000 +0200
+++ objc-list.h 2009-01-16 21:05:04.000000000 +0100
@@ -106,7 +106,11 @@
{
while (*list) {
if ((*list)->head == elem)
- list_remove_head(list);
+ {
+ list_remove_head(list);
+ continue;
+ }
+
list = &((*list)->tail);
}
}
--
Summary: Two problem in objc-list.h in list_remove_elem
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libobjc
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bartosz dot kuzma at gmail dot com
GCC host triplet: i386--netbsdelf
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38881