From fbb1b130bd5eea89e42e0ed66531657c7319737e Mon Sep 17 00:00:00 2001 From: mccallum Date: Mon, 2 Sep 1996 15:53:47 +0000 Subject: [PATCH] ([NSString -substringFromRange:]): Fix bug in references to string length. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1677 72102866-910b-0410-8b05-ffd578937521 --- Source/NSString.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/NSString.m b/Source/NSString.m index b3cde2c93..a5eb44428 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -484,10 +484,11 @@ handle_printf_atsign (FILE *stream, - (NSString*) substringFromRange: (NSRange)aRange { unichar buffer[aRange.length]; + int count = [self length]; - if (aRange.location > _count) + if (aRange.location > count) [NSException raise: NSRangeException format: @"Invalid location."]; - if (aRange.length > (_count - aRange.location)) + if (aRange.length > (count - aRange.location)) [NSException raise: NSRangeException format: @"Invalid location+length."]; [self getCharacters: buffer range: aRange]; return [[self class] stringWithCharacters: buffer length: aRange.length];