mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 01:31:08 +00:00
Fix stack overflow problem
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@20016 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
420c49dd17
commit
1b371d7744
3 changed files with 32 additions and 11 deletions
|
@ -1,3 +1,8 @@
|
|||
2004-09-07 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSSet.m:
|
||||
* Source/GSSet.m: ([allObjects]) Fix stack overflow for large sets.
|
||||
|
||||
2004-09-07 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSArray.m:
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "Foundation/NSObjCRuntime.h"
|
||||
// For private method _decodeArrayOfObjectsForKey:
|
||||
#include "Foundation/NSKeyedArchiver.h"
|
||||
#include "GSPrivate.h"
|
||||
|
||||
#define GSI_MAP_HAS_VALUE 0
|
||||
#define GSI_MAP_KTYPES GSUNION_OBJ
|
||||
|
@ -117,19 +118,22 @@ static Class mutableSetClass;
|
|||
|
||||
- (NSArray*) allObjects
|
||||
{
|
||||
id objs[map.nodeCount];
|
||||
GSIMapEnumerator_t enumerator = GSIMapEnumeratorForMap(&map);
|
||||
GSIMapNode node = GSIMapEnumeratorNextNode(&enumerator);
|
||||
unsigned i = 0;
|
||||
NSArray *result;
|
||||
GS_BEGINIDBUF(objects, map.nodeCount);
|
||||
|
||||
while (node != 0)
|
||||
{
|
||||
objs[i++] = node->key.obj;
|
||||
objects[i++] = node->key.obj;
|
||||
node = GSIMapEnumeratorNextNode(&enumerator);
|
||||
}
|
||||
GSIMapEndEnumerator(&enumerator);
|
||||
return AUTORELEASE([[arrayClass allocWithZone: NSDefaultMallocZone()]
|
||||
initWithObjects: objs count: i]);
|
||||
result = AUTORELEASE([[arrayClass allocWithZone: NSDefaultMallocZone()]
|
||||
initWithObjects: objects count: i]);
|
||||
GS_ENDIDBUF();
|
||||
return result;
|
||||
}
|
||||
|
||||
- (id) anyObject
|
||||
|
@ -137,11 +141,18 @@ static Class mutableSetClass;
|
|||
if (map.nodeCount > 0)
|
||||
{
|
||||
GSIMapBucket bucket = map.buckets;
|
||||
while(1)
|
||||
if(bucket->firstNode)
|
||||
return bucket->firstNode->key.obj;
|
||||
else
|
||||
bucket++;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (bucket->firstNode)
|
||||
{
|
||||
return bucket->firstNode->key.obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
bucket++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
// For private method _decodeArrayOfObjectsForKey:
|
||||
#include "Foundation/NSKeyedArchiver.h"
|
||||
#include "GNUstepBase/GSCategories.h"
|
||||
#include "GSPrivate.h"
|
||||
|
||||
@class GSSet;
|
||||
@class GSMutableSet;
|
||||
|
@ -417,8 +418,10 @@ static Class NSMutableSet_concrete_class;
|
|||
- (NSArray*) allObjects
|
||||
{
|
||||
id e = [self objectEnumerator];
|
||||
unsigned i, c = [self count];
|
||||
id k[c];
|
||||
unsigned i;
|
||||
unsigned c = [self count];
|
||||
NSArray *result;
|
||||
GS_BEGINIDBUF(k, c);
|
||||
|
||||
for (i = 0; i < c; i++)
|
||||
{
|
||||
|
@ -426,6 +429,8 @@ static Class NSMutableSet_concrete_class;
|
|||
}
|
||||
return AUTORELEASE([[NSArray allocWithZone: NSDefaultMallocZone()]
|
||||
initWithObjects: k count: c]);
|
||||
GS_ENDIDBUF();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue