discuss-gnustep
[Top][All Lists]
Advanced

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

Crash in countByEnumeratingWithState method of GNUstep's implementation


From: Mathias Bauer
Subject: Crash in countByEnumeratingWithState method of GNUstep's implementation of NSArray
Date: Wed, 08 Jan 2014 10:45:52 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

Hi,

it seems that the implementation of countByEnumeratingWithState in NSArray is broken.

The following code in NSArray.m

 {
   NSUInteger size = [self count];
   NSInteger count;

   /* This is cached in the caller at the start and compared at each
    * iteration.   If it changes during the iteration then
    * objc_enumerationMutation() will be called, throwing an exception.
    */
   state->mutationsPtr = (unsigned long *)size;

of course crashes as soon as any fast enumeration is executed for any collection deriving from NSArray. The cast in the last line can't work.

Now I'm wondering how this problem could remain undiscovered or at least unfixed for such a long time. I doubt that everybody who implemented a class that derives from NSArray also re-implemented this method.

A simple fix would be to add an iVar that gets the result of [self count] each time this method is called and assigning its address to state->mutationsPtr.

Any chance for getting this fixed in the trunk version?

Regards,
Mathias



reply via email to

[Prev in Thread] Current Thread [Next in Thread]