Bug 38881 - Two problem in objc-list.h in list_remove_elem
Summary: Two problem in objc-list.h in list_remove_elem
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: libobjc (show other bugs)
Version: 4.1.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-16 20:08 UTC by Bartosz Kuzma
Modified: 2010-09-17 16:53 UTC (History)
1 user (show)

See Also:
Host: i386--netbsdelf
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bartosz Kuzma 2009-01-16 20:08:09 UTC
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);
   }
 }
Comment 1 Nicola Pero 2010-09-17 16:53:53 UTC
Thanks

well spotted :-)

Unfortunately, the list_remove_elem() function is obsolete (never used inside the runtime itself, and deprecated for usage outside of it as of 4.6.0) so there is not much point in working on it any more. ;-)

Thanks