You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current rangeOfTextList:atIndex: implementation will lock up when two paragraphs with different styles and different textlists are adjacent. I found this while looking into #294 (the issue is far more likely to surface when #294 is fixed because attribute ranges aren't incorrectly merged). A fix for #293 would also likely depend on this being fixed.
The following example will reproduce the issue:
- (void) causeRangeOfTextListProblem
{
// Create two lists
NSTextList *list1 = [[NSTextList alloc] initWithMarkerFormat: @"{decimal}" options: 0];
NSTextList *list2 = [[NSTextList alloc] initWithMarkerFormat: @"{box}" options: 0];
// Create two paragraph styles
NSMutableParagraphStyle *style1 = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
NSMutableParagraphStyle *style2 = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
// Change the paragraph styles so that they don't get merged together (equality testing problems)
[style1 setHeadIndent: 36.0];
[style2 setHeadIndent: 72.0];
// Use one list per paragraph style
[style1 setTextLists: [NSArray arrayWithObject: list1]];
[style2 setTextLists: [NSArray arrayWithObject: list2]];
// Create an attributed string for each list
NSAttributedString *str1 = [[NSAttributedString alloc]
initWithString: [NSString stringWithFormat: @"%@ list1\n", [list1 markerForItemNumber: 1]]
attributes: [NSDictionary dictionaryWithObject: style1 forKey: NSParagraphStyleAttributeName]];
NSAttributedString *str2 = [[NSAttributedString alloc]
initWithString: [NSString stringWithFormat: @"%@ list2\n", [list2 markerForItemNumber: 1]]
attributes: [NSDictionary dictionaryWithObject: style2 forKey: NSParagraphStyleAttributeName]];
// Append the attributed strings to the text storage
NSTextStorage *textStorage = [textView textStorage];
[textStorage appendAttributedString: str1];
[textStorage appendAttributedString: str2];
// Attempt to find the list range for one of the two adjacent lists
// This causes a problem and the call will not return
NSLog(@"Preparing to find list range...");
NSRange range = [textStorage rangeOfTextList: list2 atIndex: [textStorage length] - 5];
NSLog(@"Found range %@", NSStringFromRange(range));
}
I'm guessing it's getting stuck in an infinite loop in one of two places in the code. Perhaps not finding the specified list in the current textLists should also be a terminating condition for the loops: What if we get the style and the textLists, but don't advance the effective range because the list we have isn't included in the textLists, so the loop repeats forever.
if ((textLists != nil) && [textLists containsObject: list])
{
effRange.length += newEffRange.length;
}
}
}
return effRange;
}
}
returnNSMakeRange(NSNotFound, 0);
}
Similar implementations exist for text blocks and text tables which may have the same problem, but I haven't looked at those at all.
(I can try to put together a PR for these issues if there's interest in your end, but I just installed GNUStep a couple of days ago and don't have a proper build/development set up yet.)
The text was updated successfully, but these errors were encountered:
The current
rangeOfTextList:atIndex:
implementation will lock up when two paragraphs with different styles and different textlists are adjacent. I found this while looking into #294 (the issue is far more likely to surface when #294 is fixed because attribute ranges aren't incorrectly merged). A fix for #293 would also likely depend on this being fixed.The following example will reproduce the issue:
I'm guessing it's getting stuck in an infinite loop in one of two places in the code. Perhaps not finding the specified list in the current
textLists
should also be a terminating condition for the loops: What if we get the style and the textLists, but don't advance the effective range because the list we have isn't included in the textLists, so the loop repeats forever.libs-gui/Source/NSAttributedString.m
Lines 1170 to 1225 in fb61a0f
Similar implementations exist for text blocks and text tables which may have the same problem, but I haven't looked at those at all.
(I can try to put together a PR for these issues if there's interest in your end, but I just installed GNUStep a couple of days ago and don't have a proper build/development set up yet.)
The text was updated successfully, but these errors were encountered: