Minor bugfix

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6395 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2000-03-28 14:29:37 +00:00
parent 0ed86abd4f
commit 126f4a14dc
2 changed files with 69 additions and 50 deletions

View file

@ -1,3 +1,8 @@
2000-03-28 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSDictionary.m: Fix to avoid crash on being asked to init
with contents of a nil dictionary.
2000-03-28 Richard Frith-Macdonald <rfm@gnu.org> 2000-03-28 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/gnustep/base/NSRunLoop.h: Added event type for exceptional * Headers/gnustep/base/NSRunLoop.h: Added event type for exceptional

View file

@ -329,6 +329,9 @@ static SEL appSel = @selector(appendString:);
- (id) initWithDictionary: (NSDictionary*)other copyItems: (BOOL)shouldCopy - (id) initWithDictionary: (NSDictionary*)other copyItems: (BOOL)shouldCopy
{ {
unsigned c = [other count]; unsigned c = [other count];
if (c > 0)
{
id os[c]; id os[c];
id ks[c]; id ks[c];
id k; id k;
@ -354,7 +357,6 @@ static SEL appSel = @selector(appendString:);
[os[--i] release]; [os[--i] release];
} }
#endif #endif
return self;
} }
else else
{ {
@ -364,8 +366,10 @@ static SEL appSel = @selector(appendString:);
os[i] = (*otherObj)(other, objSel, k); os[i] = (*otherObj)(other, objSel, k);
i++; i++;
} }
return [self initWithObjects: os forKeys: ks count: c]; self = [self initWithObjects: os forKeys: ks count: c];
} }
}
return self;
} }
- (id) initWithContentsOfFile: (NSString*)path - (id) initWithContentsOfFile: (NSString*)path
@ -418,10 +422,16 @@ static SEL appSel = @selector(appendString:);
- (BOOL) isEqualToDictionary: (NSDictionary*)other - (BOOL) isEqualToDictionary: (NSDictionary*)other
{ {
if (other == self) unsigned count;
return YES;
if ([self count] == [other count]) if (other == self)
{
return YES;
}
count = [self count];
if (count == [other count])
{
if (count > 0)
{ {
NSEnumerator *e = [self keyEnumerator]; NSEnumerator *e = [self keyEnumerator];
IMP nxtObj = [e methodForSelector: nxtSel]; IMP nxtObj = [e methodForSelector: nxtSel];
@ -437,6 +447,7 @@ static SEL appSel = @selector(appendString:);
if ([o1 isEqual: o2] == NO) if ([o1 isEqual: o2] == NO)
return NO; return NO;
} }
}
return YES; return YES;
} }
return NO; return NO;
@ -944,7 +955,7 @@ static NSString *indentStrings[] = {
{ {
unsigned c = [keyArray count]; unsigned c = [keyArray count];
if (c) if (c > 0)
{ {
id keys[c]; id keys[c];
IMP remObj = [self methodForSelector: remSel]; IMP remObj = [self methodForSelector: remSel];
@ -959,6 +970,8 @@ static NSString *indentStrings[] = {
- (void) addEntriesFromDictionary: (NSDictionary*)other - (void) addEntriesFromDictionary: (NSDictionary*)other
{ {
if (other != nil)
{
id k; id k;
NSEnumerator *e = [other keyEnumerator]; NSEnumerator *e = [other keyEnumerator];
IMP nxtObj = [e methodForSelector: nxtSel]; IMP nxtObj = [e methodForSelector: nxtSel];
@ -966,6 +979,7 @@ static NSString *indentStrings[] = {
while ((k = (*nxtObj)(e, nxtSel)) != nil) while ((k = (*nxtObj)(e, nxtSel)) != nil)
(*setObj)(self, setSel, [other objectForKey: k], k); (*setObj)(self, setSel, [other objectForKey: k], k);
}
} }
- (void) setDictionary: (NSDictionary*)otherDictionary - (void) setDictionary: (NSDictionary*)otherDictionary