Skip to content

Commit

Permalink
fix potential crash when get attribute from NSAttributedString with i…
Browse files Browse the repository at this point in the history
…nvalid index.
  • Loading branch information
ibireme committed Sep 13, 2016
1 parent 01da280 commit e1cfc1d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion YYText/Utility/NSAttributedString+YYText.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ + (instancetype)yy_unarchiveFromData:(NSData *)data {
}

- (NSDictionary *)yy_attributesAtIndex:(NSUInteger)index {
if (index > self.length || self.length == 0) return nil;
if (self.length > 0 && index == self.length) index--;
return [self attributesAtIndex:index effectiveRange:NULL];
}

- (id)yy_attribute:(NSString *)attributeName atIndex:(NSUInteger)index {
if (!attributeName) return nil;
if (self.length == 0) return nil;
if (index > self.length || self.length == 0) return nil;
if (self.length > 0 && index == self.length) index--;
return [self attribute:attributeName atIndex:index effectiveRange:NULL];
}
Expand Down

0 comments on commit e1cfc1d

Please sign in to comment.