gnustep-dev
[Top][All Lists]
Advanced

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

Possible NSAttributedString bug


From: Derek Fawcus
Subject: Possible NSAttributedString bug
Date: Thu, 1 Oct 2009 13:59:45 +0100
User-agent: Mutt/1.4.1i

I suspect there is a bug here (and maybe in the mutable version as well - I 
haven't tried it),
in that '-initWithString:attributes:' does not retain the attribute dictionary.

Using the following chunk of code:

static NSTextStorage *textStorage;

void do_tv (void)
{
        NSDictionary *attr;
        NSAttributedString *text;
        NSMutableParagraphStyle *ps =
                [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
        [ps setAlignment: NSLeftTextAlignment];
        [ps setLineBreakMode: NSLineBreakByCharWrapping];

        attr = [NSDictionary dictionaryWithObjectsAndKeys:
                        ps, NSParagraphStyleAttributeName,
                        nil, nil];
        [ps release];
        text = [[NSAttributedString alloc]
                initWithString:         @"This is the default string.\n"
                attributes:             attr];
        [attr release];

        textStorage = [[NSTextStorage alloc] init];
        [textStorage appendAttributedString: text];
        [text release];

...

I find that the app displaying the text crashes.  Removing the release of attr
prevents the crash, but would seem to leak memory.  The above works on OSX 
10.4.11;
and I was finding it failing on base-1.18, gui/back-0.16

>From a quick glance at the code,  I suspect something is wrong in 
>GSAttributedString
where the code attempts to 'cache' the attributes,  and refers to making a 
shallow
copy without copying objects.

DF




reply via email to

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