mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 09:41:15 +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>
|
2004-09-07 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSArray.m:
|
* Source/NSArray.m:
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include "Foundation/NSObjCRuntime.h"
|
#include "Foundation/NSObjCRuntime.h"
|
||||||
// For private method _decodeArrayOfObjectsForKey:
|
// For private method _decodeArrayOfObjectsForKey:
|
||||||
#include "Foundation/NSKeyedArchiver.h"
|
#include "Foundation/NSKeyedArchiver.h"
|
||||||
|
#include "GSPrivate.h"
|
||||||
|
|
||||||
#define GSI_MAP_HAS_VALUE 0
|
#define GSI_MAP_HAS_VALUE 0
|
||||||
#define GSI_MAP_KTYPES GSUNION_OBJ
|
#define GSI_MAP_KTYPES GSUNION_OBJ
|
||||||
|
@ -117,19 +118,22 @@ static Class mutableSetClass;
|
||||||
|
|
||||||
- (NSArray*) allObjects
|
- (NSArray*) allObjects
|
||||||
{
|
{
|
||||||
id objs[map.nodeCount];
|
|
||||||
GSIMapEnumerator_t enumerator = GSIMapEnumeratorForMap(&map);
|
GSIMapEnumerator_t enumerator = GSIMapEnumeratorForMap(&map);
|
||||||
GSIMapNode node = GSIMapEnumeratorNextNode(&enumerator);
|
GSIMapNode node = GSIMapEnumeratorNextNode(&enumerator);
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
|
NSArray *result;
|
||||||
|
GS_BEGINIDBUF(objects, map.nodeCount);
|
||||||
|
|
||||||
while (node != 0)
|
while (node != 0)
|
||||||
{
|
{
|
||||||
objs[i++] = node->key.obj;
|
objects[i++] = node->key.obj;
|
||||||
node = GSIMapEnumeratorNextNode(&enumerator);
|
node = GSIMapEnumeratorNextNode(&enumerator);
|
||||||
}
|
}
|
||||||
GSIMapEndEnumerator(&enumerator);
|
GSIMapEndEnumerator(&enumerator);
|
||||||
return AUTORELEASE([[arrayClass allocWithZone: NSDefaultMallocZone()]
|
result = AUTORELEASE([[arrayClass allocWithZone: NSDefaultMallocZone()]
|
||||||
initWithObjects: objs count: i]);
|
initWithObjects: objects count: i]);
|
||||||
|
GS_ENDIDBUF();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) anyObject
|
- (id) anyObject
|
||||||
|
@ -137,12 +141,19 @@ static Class mutableSetClass;
|
||||||
if (map.nodeCount > 0)
|
if (map.nodeCount > 0)
|
||||||
{
|
{
|
||||||
GSIMapBucket bucket = map.buckets;
|
GSIMapBucket bucket = map.buckets;
|
||||||
while(1)
|
|
||||||
if(bucket->firstNode)
|
while (1)
|
||||||
|
{
|
||||||
|
if (bucket->firstNode)
|
||||||
|
{
|
||||||
return bucket->firstNode->key.obj;
|
return bucket->firstNode->key.obj;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
bucket++;
|
bucket++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return nil;
|
return nil;
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
// For private method _decodeArrayOfObjectsForKey:
|
// For private method _decodeArrayOfObjectsForKey:
|
||||||
#include "Foundation/NSKeyedArchiver.h"
|
#include "Foundation/NSKeyedArchiver.h"
|
||||||
#include "GNUstepBase/GSCategories.h"
|
#include "GNUstepBase/GSCategories.h"
|
||||||
|
#include "GSPrivate.h"
|
||||||
|
|
||||||
@class GSSet;
|
@class GSSet;
|
||||||
@class GSMutableSet;
|
@class GSMutableSet;
|
||||||
|
@ -417,8 +418,10 @@ static Class NSMutableSet_concrete_class;
|
||||||
- (NSArray*) allObjects
|
- (NSArray*) allObjects
|
||||||
{
|
{
|
||||||
id e = [self objectEnumerator];
|
id e = [self objectEnumerator];
|
||||||
unsigned i, c = [self count];
|
unsigned i;
|
||||||
id k[c];
|
unsigned c = [self count];
|
||||||
|
NSArray *result;
|
||||||
|
GS_BEGINIDBUF(k, c);
|
||||||
|
|
||||||
for (i = 0; i < c; i++)
|
for (i = 0; i < c; i++)
|
||||||
{
|
{
|
||||||
|
@ -426,6 +429,8 @@ static Class NSMutableSet_concrete_class;
|
||||||
}
|
}
|
||||||
return AUTORELEASE([[NSArray allocWithZone: NSDefaultMallocZone()]
|
return AUTORELEASE([[NSArray allocWithZone: NSDefaultMallocZone()]
|
||||||
initWithObjects: k count: c]);
|
initWithObjects: k count: c]);
|
||||||
|
GS_ENDIDBUF();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue