From b0faa3a93089dc99ea49542545db4c17251a93f3 Mon Sep 17 00:00:00 2001 From: Frederick John Milens III Date: Tue, 24 Sep 2024 18:58:55 -0500 Subject: [PATCH 01/10] NSTextLists should use NSObject's default isEqual: --- Source/NSTextList.m | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/Source/NSTextList.m b/Source/NSTextList.m index 080735b61..70f3aac04 100644 --- a/Source/NSTextList.m +++ b/Source/NSTextList.m @@ -51,21 +51,6 @@ [super dealloc]; } -- (BOOL) isEqual: (id)anObject -{ - if (anObject == self) - { - return YES; - } - if (anObject == nil || [anObject isKindOfClass: [NSTextList class]] == NO) - { - return NO; - } - - return ([anObject listOptions] == _listOptions) - && [_markerFormat isEqualToString: [anObject markerFormat]]; -} - - (unsigned int) listOptions { return _listOptions; From 9d63a862eb7bad64e76cf0bac80d73573c8f4a72 Mon Sep 17 00:00:00 2001 From: Frederick John Milens III Date: Tue, 24 Sep 2024 20:08:45 -0500 Subject: [PATCH 02/10] Include NSTextLists in NSParagraphStyle isEqual: tests --- Source/NSParagraphStyle.m | 7 +++- .../NSParagraphStyle_equalityTesting.m | 38 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 Tests/gui/NSParagraphStyle/NSParagraphStyle_equalityTesting.m diff --git a/Source/NSParagraphStyle.m b/Source/NSParagraphStyle.m index 468b72c44..04de3d9a1 100644 --- a/Source/NSParagraphStyle.m +++ b/Source/NSParagraphStyle.m @@ -621,7 +621,12 @@ static NSParagraphStyle *defaultStyle = nil; C(_headerLevel); #undef C - return [_tabStops isEqualToArray: other->_tabStops]; +#define C(x) if (![x isEqualToArray: other->x]) return NO; + C(_tabStops); + C(_textLists); +#undef C + + return YES; } - (NSUInteger) hash diff --git a/Tests/gui/NSParagraphStyle/NSParagraphStyle_equalityTesting.m b/Tests/gui/NSParagraphStyle/NSParagraphStyle_equalityTesting.m new file mode 100644 index 000000000..74c50ce6f --- /dev/null +++ b/Tests/gui/NSParagraphStyle/NSParagraphStyle_equalityTesting.m @@ -0,0 +1,38 @@ +#include "Testing.h" + +#include +#include +#include + +int main(int argc, char **argv) +{ + CREATE_AUTORELEASE_POOL(arp); + + START_SET("NSParagraphStyle equality tests"); + + NSMutableParagraphStyle *default1 = [NSParagraphStyle defaultParagraphStyle]; + NSMutableParagraphStyle *default2 = [NSParagraphStyle defaultParagraphStyle]; + + PASS_EQUAL(default1, default2, "NSParagraphStyle isEqual: works for default paragraph styles"); + + NSMutableParagraphStyle *style1 = [[NSMutableParagraphStyle alloc] init]; + NSMutableParagraphStyle *style2 = [[NSMutableParagraphStyle alloc] init]; + + NSTextList *textList = [[NSTextList alloc] init]; + + [style1 setTextLists: [NSArray arrayWithObject: textList]]; + [style2 setTextLists: [NSArray arrayWithObject: textList]]; + + PASS_EQUAL(style1, style2, "NSParagraphStyle isEqual: works for identical textlists"); + + [style1 setTextLists: [NSArray arrayWithObject: [[NSTextList alloc] init]]]; + [style2 setTextLists: [NSArray arrayWithObject: [[NSTextList alloc] init]]]; + + pass(![style1 isEqual: style2], "NSParagraphStyle isEqual: works for different textlists"); + + END_SET("NSParagraphStyle equality tests"); + + DESTROY(arp); + + return 0; +} From 3c478471dc86b55440bc5d66cfd40686ecef0539 Mon Sep 17 00:00:00 2001 From: Frederick John Milens III Date: Tue, 24 Sep 2024 22:46:28 -0500 Subject: [PATCH 03/10] Include empty array as _textLists default value --- Source/NSParagraphStyle.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/NSParagraphStyle.m b/Source/NSParagraphStyle.m index 04de3d9a1..a3f00eefb 100644 --- a/Source/NSParagraphStyle.m +++ b/Source/NSParagraphStyle.m @@ -303,6 +303,8 @@ static NSParagraphStyle *defaultStyle = nil; [_tabStops addObject: tab]; RELEASE(tab); } + + ASSIGN(_textLists, [NSArray array]); } return self; } @@ -494,6 +496,9 @@ static NSParagraphStyle *defaultStyle = nil; [aCoder decodeValueOfObjCType: @encode(float) at: &_paragraphSpacing]; [aCoder decodeValueOfObjCType: @encode(float) at: &_tailIndent]; + // Text lists were not included for non-keyed encoding, use a default + ASSIGN(_textLists, [NSArray array]); + /* * Tab stops don't conform to NSCoding - so we do it the long way. */ From 44a42ddc03b55ba595b6755e6a6e5bf8f869d5f2 Mon Sep 17 00:00:00 2001 From: Frederick John Milens III Date: Tue, 24 Sep 2024 22:48:09 -0500 Subject: [PATCH 04/10] Update test case --- .../NSParagraphStyle/NSParagraphStyle_equalityTesting.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Tests/gui/NSParagraphStyle/NSParagraphStyle_equalityTesting.m b/Tests/gui/NSParagraphStyle/NSParagraphStyle_equalityTesting.m index 74c50ce6f..443dfa822 100644 --- a/Tests/gui/NSParagraphStyle/NSParagraphStyle_equalityTesting.m +++ b/Tests/gui/NSParagraphStyle/NSParagraphStyle_equalityTesting.m @@ -5,9 +5,9 @@ #include int main(int argc, char **argv) -{ +{ CREATE_AUTORELEASE_POOL(arp); - + START_SET("NSParagraphStyle equality tests"); NSMutableParagraphStyle *default1 = [NSParagraphStyle defaultParagraphStyle]; @@ -18,6 +18,8 @@ int main(int argc, char **argv) NSMutableParagraphStyle *style1 = [[NSMutableParagraphStyle alloc] init]; NSMutableParagraphStyle *style2 = [[NSMutableParagraphStyle alloc] init]; + PASS_EQUAL(style1, style2, "NSParagraphStyle isEqual: works for default mutable copies"); + NSTextList *textList = [[NSTextList alloc] init]; [style1 setTextLists: [NSArray arrayWithObject: textList]]; @@ -29,7 +31,7 @@ int main(int argc, char **argv) [style2 setTextLists: [NSArray arrayWithObject: [[NSTextList alloc] init]]]; pass(![style1 isEqual: style2], "NSParagraphStyle isEqual: works for different textlists"); - + END_SET("NSParagraphStyle equality tests"); DESTROY(arp); From 7f42e27a5272a2646f49f6b329d1326b30dc8209 Mon Sep 17 00:00:00 2001 From: Frederick John Milens III Date: Tue, 24 Sep 2024 22:50:12 -0500 Subject: [PATCH 05/10] Add integration-like test to verify paragraph style merging --- .../NSAttributedString_mergingAttributes.m | 73 +++++++++++++++++++ Tests/gui/NSAttributedString/TestInfo | 0 2 files changed, 73 insertions(+) create mode 100644 Tests/gui/NSAttributedString/NSAttributedString_mergingAttributes.m create mode 100644 Tests/gui/NSAttributedString/TestInfo diff --git a/Tests/gui/NSAttributedString/NSAttributedString_mergingAttributes.m b/Tests/gui/NSAttributedString/NSAttributedString_mergingAttributes.m new file mode 100644 index 000000000..e3b4adfd1 --- /dev/null +++ b/Tests/gui/NSAttributedString/NSAttributedString_mergingAttributes.m @@ -0,0 +1,73 @@ +#include "Testing.h" + +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + CREATE_AUTORELEASE_POOL(arp); + + START_SET("NSAttributedString attribute merging"); + + NSMutableParagraphStyle *style1 = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + NSMutableParagraphStyle *style2 = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + NSMutableParagraphStyle *style3 = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + NSMutableParagraphStyle *style4 = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + + NSTextList *list1 = [[NSTextList alloc] initWithMarkerFormat: @"{box}" options: 0]; + NSTextList *list2 = [[NSTextList alloc] initWithMarkerFormat: @"{box}" options: 0]; + + [style3 setTextLists: [NSArray arrayWithObject: list1]]; + [style4 setTextLists: [NSArray arrayWithObject: list2]]; + + NSAttributedString *str1 = [[NSAttributedString alloc] + initWithString: @"string 1" + attributes: [NSDictionary dictionaryWithObject: style1 forKey: NSParagraphStyleAttributeName]]; + NSAttributedString *str2 = [[NSAttributedString alloc] + initWithString: @"string 2" + attributes: [NSDictionary dictionaryWithObject: style2 forKey: NSParagraphStyleAttributeName]]; + NSAttributedString *str3 = [[NSAttributedString alloc] + initWithString: @"string 3" + attributes: [NSDictionary dictionaryWithObject: style3 forKey: NSParagraphStyleAttributeName]]; + NSAttributedString *str4 = [[NSAttributedString alloc] + initWithString: @"string 4" + attributes: [NSDictionary dictionaryWithObject: style4 forKey: NSParagraphStyleAttributeName]]; + + NSMutableAttributedString *storage = [[NSMutableAttributedString alloc] init]; + + NSUInteger pos1 = [storage length]; + [storage appendAttributedString: str1]; + + NSUInteger pos2 = [storage length]; + [storage appendAttributedString: str2]; + + NSUInteger pos3 = [storage length]; + [storage appendAttributedString: str3]; + + NSUInteger pos4 = [storage length]; + [storage appendAttributedString: str4]; + + NSParagraphStyle *result1 = [storage attribute: NSParagraphStyleAttributeName + atIndex: pos1 + effectiveRange: NULL]; + NSParagraphStyle *result2 = [storage attribute: NSParagraphStyleAttributeName + atIndex: pos2 + effectiveRange: NULL]; + NSParagraphStyle *result3 = [storage attribute: NSParagraphStyleAttributeName + atIndex: pos3 + effectiveRange: NULL]; + NSParagraphStyle *result4 = [storage attribute: NSParagraphStyleAttributeName + atIndex: pos4 + effectiveRange: NULL]; + + pass(result1 == result2, "Did merge equal paragraph styles"); + pass(result3 != result4, "Did not merge equal paragraph styles with text lists"); + + END_SET("NSAttributedString attribute merging"); + + DESTROY(arp); + + return 0; +} diff --git a/Tests/gui/NSAttributedString/TestInfo b/Tests/gui/NSAttributedString/TestInfo new file mode 100644 index 000000000..e69de29bb From 2bfb0bda93a3937083fb8baae87de8455886718e Mon Sep 17 00:00:00 2001 From: Frederick John Milens III Date: Wed, 25 Sep 2024 00:22:46 -0500 Subject: [PATCH 06/10] Fix and test cases for NSAttributedString rangeOfTextList:atIndex: lockups --- Source/NSAttributedString.m | 8 +- .../NSAttributedString_rangeOfTextList.m | 88 +++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 Tests/gui/NSAttributedString/NSAttributedString_rangeOfTextList.m diff --git a/Source/NSAttributedString.m b/Source/NSAttributedString.m index cfca61f55..fde2b1cd4 100644 --- a/Source/NSAttributedString.m +++ b/Source/NSAttributedString.m @@ -1183,7 +1183,7 @@ documentAttributes: (NSDictionary **)dict NSRange newEffRange; NSUInteger len = [self length]; - while ((effRange.location > 0) && style && textLists) + while (effRange.location > 0) { style = [self attribute: NSParagraphStyleAttributeName atIndex: effRange.location - 1 @@ -1196,11 +1196,13 @@ documentAttributes: (NSDictionary **)dict { effRange.location = newEffRange.location; effRange.length += newEffRange.length; + continue; } } + break; } - while (NSMaxRange(effRange) < len && style && textLists) + while (NSMaxRange(effRange) < len) { style = [self attribute: NSParagraphStyleAttributeName atIndex: NSMaxRange(effRange) @@ -1212,8 +1214,10 @@ documentAttributes: (NSDictionary **)dict if ((textLists != nil) && [textLists containsObject: list]) { effRange.length += newEffRange.length; + continue; } } + break; } return effRange; diff --git a/Tests/gui/NSAttributedString/NSAttributedString_rangeOfTextList.m b/Tests/gui/NSAttributedString/NSAttributedString_rangeOfTextList.m new file mode 100644 index 000000000..62dfb0cf0 --- /dev/null +++ b/Tests/gui/NSAttributedString/NSAttributedString_rangeOfTextList.m @@ -0,0 +1,88 @@ +#include "Testing.h" + +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + CREATE_AUTORELEASE_POOL(arp); + + START_SET("NSAttributedString rangeOfTextList:atIndex: category method"); + + NSTextList *list1 = [[NSTextList alloc] initWithMarkerFormat: @"{box}" options: 0]; + NSTextList *list2 = [[NSTextList alloc] initWithMarkerFormat: @"{box}" options: 0]; + NSTextList *list3 = [[NSTextList alloc] initWithMarkerFormat: @"{box}" options: 0]; + + NSMutableParagraphStyle *style1 = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + NSMutableParagraphStyle *style2 = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + NSMutableParagraphStyle *style3 = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + NSMutableParagraphStyle *style4 = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + + [style2 setTextLists: [NSArray arrayWithObject: list1]]; + [style3 setTextLists: [NSArray arrayWithObjects: list1, list2, nil]]; + [style4 setTextLists: [NSArray arrayWithObject: list3]]; + + NSMutableAttributedString *storage = [[NSMutableAttributedString alloc] init]; + + NSUInteger pos1 = [storage length]; + [storage appendAttributedString: [[NSAttributedString alloc] + initWithString: @"before\n" + attributes: [NSDictionary dictionaryWithObject: style1 forKey: NSParagraphStyleAttributeName]]]; + + NSUInteger pos2 = [storage length]; + [storage appendAttributedString: [[NSAttributedString alloc] + initWithString: @"list 1\n" + attributes: [NSDictionary dictionaryWithObject: style2 forKey: NSParagraphStyleAttributeName]]]; + + NSUInteger pos3 = [storage length]; + [storage appendAttributedString: [[NSAttributedString alloc] + initWithString: @"sublist 1\n" + attributes: [NSDictionary dictionaryWithObject: style3 forKey: NSParagraphStyleAttributeName]]]; + + NSUInteger pos4 = [storage length]; + [storage appendAttributedString: [[NSAttributedString alloc] + initWithString: @"list 1\n" + attributes: [NSDictionary dictionaryWithObject: style2 forKey: NSParagraphStyleAttributeName]]]; + + NSUInteger pos5 = [storage length]; + [storage appendAttributedString: [[NSAttributedString alloc] + initWithString: @"list 2\n" + attributes: [NSDictionary dictionaryWithObject: style4 forKey: NSParagraphStyleAttributeName]]]; + + NSUInteger pos6 = [storage length]; + [storage appendAttributedString: [[NSAttributedString alloc] + initWithString: @"ending\n" + attributes: [NSDictionary dictionaryWithObject: style1 forKey: NSParagraphStyleAttributeName]]]; + + NSRange expected, actual; + + expected = NSMakeRange(pos3, pos4 - pos3); + actual = [storage rangeOfTextList: list2 atIndex: pos3 + 1]; + pass(NSEqualRanges(expected, actual), "Found correct range of nested list"); + + expected = NSMakeRange(pos2, pos5 - pos2); + actual = [storage rangeOfTextList: list1 atIndex: pos3 + 1]; + pass(NSEqualRanges(expected, actual), "Found correct range of enclosing list"); + + expected = NSMakeRange(pos2, pos5 - pos2); + actual = [storage rangeOfTextList: list1 atIndex: pos2 + 1]; + pass(NSEqualRanges(expected, actual), "Found correct range including nested list"); + + expected = NSMakeRange(pos5, pos6 - pos5); + actual = [storage rangeOfTextList: list3 atIndex: pos5 + 1]; + pass(NSEqualRanges(expected, actual), "Found correct range of an adjacent list"); + + actual = [storage rangeOfTextList: list1 atIndex: pos5]; + pass(actual.location == NSNotFound, "Returned not found for location in different list"); + + actual = [storage rangeOfTextList: list1 atIndex: pos1]; + pass(actual.location == NSNotFound, "Returned not found for location not in any list"); + + END_SET("NSAttributedString rangeOfTextList:atIndex: category method"); + + DESTROY(arp); + + return 0; +} From 65ee82565d0c00f1746c410907fcf3af971c7368 Mon Sep 17 00:00:00 2001 From: Frederick John Milens III Date: Wed, 25 Sep 2024 20:13:56 -0500 Subject: [PATCH 07/10] Fix and test cases for NSAttributedString itemNumberInTextList:atIndex: --- Source/NSAttributedString.m | 52 +++++++++--- .../NSAttributedString_itemNumberInTextList.m | 79 +++++++++++++++++++ 2 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 Tests/gui/NSAttributedString/NSAttributedString_itemNumberInTextList.m diff --git a/Source/NSAttributedString.m b/Source/NSAttributedString.m index fde2b1cd4..b95c6e3b4 100644 --- a/Source/NSAttributedString.m +++ b/Source/NSAttributedString.m @@ -53,6 +53,7 @@ #import "AppKit/NSFont.h" #import "AppKit/NSFontDescriptor.h" #import "AppKit/NSFontManager.h" +#import "AppKit/NSTextList.h" // For the colour name spaces #import "AppKit/NSGraphics.h" #import "AppKit/NSTextTable.h" @@ -1095,20 +1096,51 @@ documentAttributes: (NSDictionary **)dict - (NSInteger) itemNumberInTextList: (NSTextList *)list atIndex: (NSUInteger)location { - NSParagraphStyle *style = [self attribute: NSParagraphStyleAttributeName - atIndex: location - effectiveRange: NULL]; - if (style != nil) + NSRange listRange = [self rangeOfTextList: list atIndex: location]; + if (listRange.location == NSNotFound) { - NSArray *textLists = [style textLists]; - - if (textLists != nil) + return 0; + } + + NSRange subRange = NSMakeRange(listRange.location, location - listRange.location + 1); + NSUInteger length = NSMaxRange(subRange); + unichar buffer[length]; + + [[self string] getCharacters: buffer range: subRange]; + + NSCharacterSet *newlineCharacterSet = [NSCharacterSet newlineCharacterSet]; + + BOOL isNested = NO; + NSUInteger itemNumber = 1; + NSUInteger index; + for (index=1; index +#include +#include +#include + +int main(int argc, char **argv) +{ + CREATE_AUTORELEASE_POOL(arp); + + START_SET("NSAttributedString itemNumberInTextList:atIndex: category method"); + + NSTextList *list1 = [[NSTextList alloc] initWithMarkerFormat:@"{decimal}" options:0]; + NSTextList *list2 = [[NSTextList alloc] initWithMarkerFormat:@"{box}" options:0]; + + NSMutableParagraphStyle *style1 = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + NSMutableParagraphStyle *style2 = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + + [style1 setTextLists: [NSArray arrayWithObject: list1]]; + [style2 setTextLists: [NSArray arrayWithObjects: list1, list2, nil]]; + + NSDictionary *attrs1 = [NSDictionary dictionaryWithObject: style1 + forKey: NSParagraphStyleAttributeName]; + NSDictionary *attrs2 = [NSDictionary dictionaryWithObject: style2 + forKey: NSParagraphStyleAttributeName]; + NSDictionary *attrs3 = [NSDictionary dictionaryWithObject: [NSParagraphStyle defaultParagraphStyle] + forKey: NSParagraphStyleAttributeName]; + + NSMutableAttributedString *storage = [[NSMutableAttributedString alloc] init]; + + NSUInteger index1 = [storage length]; + [storage appendAttributedString: + [[NSMutableAttributedString alloc] initWithString: @"item 1\r\n" attributes: attrs1]]; + + NSUInteger index2 = [storage length]; + [storage appendAttributedString: + [[NSMutableAttributedString alloc] initWithString: @"item 2\n" attributes: attrs1]]; + + NSUInteger index3 = [storage length]; + [storage appendAttributedString: + [[NSMutableAttributedString alloc] initWithString: @"item 3\n" attributes: attrs1]]; + + NSUInteger index4A = [storage length]; + [storage appendAttributedString: + [[NSMutableAttributedString alloc] initWithString: @"item 4A\n" attributes: attrs2]]; + + NSUInteger index4B = [storage length]; + [storage appendAttributedString: + [[NSMutableAttributedString alloc] initWithString: @"item 4B\n" attributes: attrs2]]; + + NSUInteger index5 = [storage length]; + [storage appendAttributedString: + [[NSMutableAttributedString alloc] initWithString: @"item 5\n" attributes: attrs1]]; + + NSUInteger index6 = [storage length]; + [storage appendAttributedString: + [[NSMutableAttributedString alloc] initWithString: @"extra text\n" attributes: attrs3]]; + + pass([storage itemNumberInTextList: list1 atIndex: index1] == 1, "Index for first list item"); + pass([storage itemNumberInTextList: list1 atIndex: index2] == 2, "Index with CR+LF sequence"); + pass([storage itemNumberInTextList: list1 atIndex: index3 - 1] == 2, "Index on boundary"); + pass([storage itemNumberInTextList: list1 atIndex: index3] == 3, "Index for third list item"); + pass([storage itemNumberInTextList: list1 atIndex: index4A] == 4, "Index for fourth list item, A"); + pass([storage itemNumberInTextList: list1 atIndex: index4B] == 4, "Index for fourth list item, B"); + pass([storage itemNumberInTextList: list1 atIndex: index5] == 5, "Index for fifth list item"); + + pass([storage itemNumberInTextList: list2 atIndex: index4A] == 1, "Index for first sublist item"); + pass([storage itemNumberInTextList: list2 atIndex: index4B] == 2, "Index for second sublist item"); + + pass([storage itemNumberInTextList: list2 atIndex: index1] == 0, "Index in other list is zero"); + pass([storage itemNumberInTextList: list1 atIndex: index6] == 0, "Index in nonlist is zero"); + + END_SET("NSAttributedString itemNumberInTextList:atIndex: category method"); + + DESTROY(arp); + + return 0; +} From b00f6e5526f37b3c46f89ee61a1c25802e005f3c Mon Sep 17 00:00:00 2001 From: Frederick John Milens III Date: Wed, 25 Sep 2024 21:21:24 -0500 Subject: [PATCH 08/10] Don't count sublists as a separate list item --- Source/NSAttributedString.m | 7 ----- .../NSAttributedString_itemNumberInTextList.m | 28 +++++++++---------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/Source/NSAttributedString.m b/Source/NSAttributedString.m index b95c6e3b4..5c4bfe01a 100644 --- a/Source/NSAttributedString.m +++ b/Source/NSAttributedString.m @@ -1110,7 +1110,6 @@ documentAttributes: (NSDictionary **)dict NSCharacterSet *newlineCharacterSet = [NSCharacterSet newlineCharacterSet]; - BOOL isNested = NO; NSUInteger itemNumber = 1; NSUInteger index; for (index=1; index Date: Wed, 25 Sep 2024 22:50:21 -0500 Subject: [PATCH 09/10] Use correct length for text range unichar buffer --- Source/NSAttributedString.m | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Source/NSAttributedString.m b/Source/NSAttributedString.m index 5c4bfe01a..df8955b38 100644 --- a/Source/NSAttributedString.m +++ b/Source/NSAttributedString.m @@ -1101,10 +1101,9 @@ documentAttributes: (NSDictionary **)dict { return 0; } - - NSRange subRange = NSMakeRange(listRange.location, location - listRange.location + 1); - NSUInteger length = NSMaxRange(subRange); - unichar buffer[length]; + + NSRange subRange = NSMakeRange(listRange.location, location-listRange.location+1); + unichar buffer[subRange.length]; [[self string] getCharacters: buffer range: subRange]; @@ -1112,12 +1111,12 @@ documentAttributes: (NSDictionary **)dict NSUInteger itemNumber = 1; NSUInteger index; - for (index=1; index Date: Thu, 26 Sep 2024 00:12:05 -0500 Subject: [PATCH 10/10] Fix typo in test case --- .../NSAttributedString_itemNumberInTextList.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/gui/NSAttributedString/NSAttributedString_itemNumberInTextList.m b/Tests/gui/NSAttributedString/NSAttributedString_itemNumberInTextList.m index 255e5370c..1043df6d4 100644 --- a/Tests/gui/NSAttributedString/NSAttributedString_itemNumberInTextList.m +++ b/Tests/gui/NSAttributedString/NSAttributedString_itemNumberInTextList.m @@ -63,7 +63,7 @@ int main(int argc, char **argv) pass([storage itemNumberInTextList: list1 atIndex: index3] == 3, "Index for third list item"); pass([storage itemNumberInTextList: list1 atIndex: index4] == 3, "Index for third list item (sublist 1)"); pass([storage itemNumberInTextList: list1 atIndex: index5] == 3, "Index for third list item (sublist 2"); - pass([storage itemNumberInTextList: list1 atIndex: index6] == 4, "Index for fifth list item"); + pass([storage itemNumberInTextList: list1 atIndex: index6] == 4, "Index for fourth list item"); pass([storage itemNumberInTextList: list2 atIndex: index4] == 1, "Index for first sublist item"); pass([storage itemNumberInTextList: list2 atIndex: index5] == 2, "Index for second sublist item");