From 0554ecb6dd8b45d05e49029c59ac4051b510f1b7 Mon Sep 17 00:00:00 2001 From: richard Date: Sat, 17 Oct 1998 05:38:46 +0000 Subject: [PATCH] Added some argument checking. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3075 72102866-910b-0410-8b05-ffd578937521 --- Source/NSGDictionary.m | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/Source/NSGDictionary.m b/Source/NSGDictionary.m index 3d049e5ca..42466270d 100644 --- a/Source/NSGDictionary.m +++ b/Source/NSGDictionary.m @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -203,6 +204,16 @@ myEqual(NSObject *self, NSObject *other) for (i = 0; i < c; i++) { FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)keys[i]); + if (keys[i] == nil) { + [NSException raise: NSInvalidArgumentException + format: @"Tried to init dictionary with nil key"]; + } + if (objs[i] == nil) { + [NSException raise: NSInvalidArgumentException + format: @"Tried to init dictionary with nil value"]; + } + + node = FastMapNodeForKey(&map, (FastMapItem)keys[i]); if (node) { [objs[i] retain]; [node->value.o release]; @@ -229,10 +240,12 @@ myEqual(NSObject *self, NSObject *other) - (id) objectForKey: aKey { - FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)aKey); + if (aKey != nil) { + FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)aKey); - if (node) - return node->value.o; + if (node) + return node->value.o; + } return nil; } @@ -257,8 +270,17 @@ myEqual(NSObject *self, NSObject *other) - (void) setObject: (NSObject*)anObject forKey: (NSObject *)aKey { - FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)aKey); + FastMapNode node; + if (aKey == nil) { + [NSException raise: NSInvalidArgumentException + format: @"Tried to add nil key to dictionary"]; + } + if (anObject == nil) { + [NSException raise: NSInvalidArgumentException + format: @"Tried to add nil value to dictionary"]; + } + node = FastMapNodeForKey(&map, (FastMapItem)aKey); if (node) { [anObject retain]; [node->value.o release]; @@ -276,7 +298,9 @@ myEqual(NSObject *self, NSObject *other) - (void) removeObjectForKey: (NSObject *)aKey { - FastMapRemoveKey(&map, (FastMapItem)aKey); + if (aKey) { + FastMapRemoveKey(&map, (FastMapItem)aKey); + } } @end