From 1b371d7744f75bd5938cec9cb6a47b50a7ce25b8 Mon Sep 17 00:00:00 2001 From: CaS Date: Tue, 7 Sep 2004 11:08:46 +0000 Subject: [PATCH] Fix stack overflow problem git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@20016 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/GSSet.m | 29 ++++++++++++++++++++--------- Source/NSSet.m | 9 +++++++-- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 44f2153a5..f168a45bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-09-07 Richard Frith-Macdonald + + * Source/NSSet.m: + * Source/GSSet.m: ([allObjects]) Fix stack overflow for large sets. + 2004-09-07 Richard Frith-Macdonald * Source/NSArray.m: diff --git a/Source/GSSet.m b/Source/GSSet.m index 4206f6325..ef98527a7 100644 --- a/Source/GSSet.m +++ b/Source/GSSet.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 { diff --git a/Source/NSSet.m b/Source/NSSet.m index e655ffca8..7d9870ab1 100644 --- a/Source/NSSet.m +++ b/Source/NSSet.m @@ -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; } /**