Roland Schwingel wrote:
> 
> Hi...
> 
> I assume a bug in NSString.m method:
> - (void) getLineStart: (unsigned *)startIndex  end: (unsigned 
> *)lineEndIndex  contentsEnd: (unsigned *)contentsEndIndex  forRange: 
> (NSRange)aRange
> 
> When you read the code carefully you will find this (about line 1852 in 
> gnustep-base-1.1.0):
> ...
>  if (lineEndIndex)
> {
>   if (end < len
>     && ((*caiImp)(self, caiSel, end) == (unichar)0x000D)
>     && ((*caiImp)(self, caiSel, end+1) == (unichar)0x000A))
>     {
>       *lineEndIndex = end+1;
>     }
>   else
>     {
>       *lineEndIndex = end;
>     }
> }
> ...
> 
> When one will assume that end and len are just one number away
> (eg end==101 and len==102 ) - what can happen when you read the whole 
> method - the
> ((*caiImp)(self, caiSel, end+1) == (unichar)0x000A) in the second if() 
> statement
> will fail with a Rangeexception in GSStrings characterAtIndex_c() 
> because you read
> one letter out of range...
> 
> If this is true maybe this should be fixed...
> 
> Roland
> 
> PS: This is my first posting to this list I hope I am right here...

Yes you are. Although since the compiler tends to optimize away the 
second check if the first one is false, it only gets triggered in rare 
circumstances (well on Windows, perhaps not so rare) with two \r at the 
end of the string, such as:

s = @"This is a line of text\r\r";

Thanks for pointing this out.



-- 
Adam Fedor, Digital Optics Corp.      | I'm glad I hate spinach, because
http://www.doc.com                    | if I didn't, I'd eat it, and you
                                       | know how I hate the stuff.


_______________________________________________
Bug-gnustep mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-gnustep

Reply via email to