discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSIternalInconsistencyException with NSMutableData


From: Richard Frith-Macdonald
Subject: Re: NSIternalInconsistencyException with NSMutableData
Date: Sun, 5 Jan 2014 17:33:43 +0000

On 5 Jan 2014, at 17:02, Fred Kiefer <fredkiefer@gmx.de> wrote:

> On 04.01.2014 06:27, Germán Arias wrote:
>> I'm having a problem with NSMutableData at GNUMail. This app declares 
>> extensions for NSData at file NSData+Extension.m, inside these methods 
>> NSMutableData objects are used. Specifically the methos 
>> -replaceBytesInRange:withBytes:length:, which causes an 
>> NSIternalInconsistencyException with message: missing bytes in 
>> replaceByteInRange:withBytes:. I thought this was because the object 
>> NSMutableData was modified before call -replaceByteInRange:withBytes:. So, I 
>> changed this and to now the bytes are removed with -setLength:, which works 
>> for me. But after re-read the documentation, I see I misunderstand this, and 
>> that -replaceBytesInRange:withBytes:length: should work.
>> 
>> The correspondign code is, the exceptions occurs at last line:
>> 
>>       // The line is fixed, we append it.
>>        [lines appendData: aLine];
>>        
>>        // We add the necessary quote characters in the paragraph
>>        if (quote_depth)
>>          {
>>            NSData *d;
>>            
>>            d = [lines quoteWithLevel: quote_depth   wrappingLimit: 
>> theQuoteLimit];
>>            [lines replaceBytesInRange: NSMakeRange(0, [lines length])
>>                   withBytes: [d bytes]  length: [d length]];
>>          }
>> 
>>        // We append the paragraph (if any)
>>        if ([lines length])
>>          {
>>            [aMutableData appendData: lines];
>>          }
>>        [aMutableData appendCString: "\n"];
>>        
>>        // We empty the paragraph buffer
>>        [lines replaceBytesInRange: NSMakeRange(0, [lines length] withBytes: 
>> NULL  length: 0];
>> 
>> 
>> Any advice?
> 
> Hi German,
> 
> first off, technical questions like this one would be better of on the
> developer mailing list.
> 
> Next if you look at the code in NSData.m you will see that this
> exception gets raised when the call [self mutableBytes] returns 0. Now
> this is one of the methods specific to each class in the class cluster.
> That means nobody is able to comment on the problem without knowing how
> "lines" gets instantiated. I tried to find the code for GNUmail on the
> internet before replying, but failed to. The official address seems to
> be dead.
> 
> Sorry for being of no help here,


I found it ... it's actually in Pantomime rather than GNUmail.
Not that that helps much.
Looking at NSData.m I think it would be possible to get this exception if you 
have an empty mutable string which has never been used (so it doesn't have a 
buffer), and try to replace a zero length range with a zero length string.  
That ought to be a no-op, so I've modified the code to check for that case and 
return without doping anything if it finds it.
Maybe the code in turnk would work now?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]