From 1e750858d0a3fa31bf9e591cb065dcb031677a9b Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Fri, 2 Oct 2020 09:46:13 -0400 Subject: Fix issue found via asan Don't try to use more bytes then there are in the string. --- Foundation/GTMRegexTest.m | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Foundation/GTMRegexTest.m') diff --git a/Foundation/GTMRegexTest.m b/Foundation/GTMRegexTest.m index 75f5aad..d43b731 100644 --- a/Foundation/GTMRegexTest.m +++ b/Foundation/GTMRegexTest.m @@ -885,6 +885,15 @@ XCTAssertNotNil(seg); XCTAssertGreaterThan([[seg description] length], (NSUInteger)10, @"failed to get a reasonable description for regex string segment"); + + // Truncation on the input string (and handling sort lengths) + enumerator = [regex segmentEnumeratorForString:@"aaabbbccc"]; + XCTAssertNotNil(enumerator); + XCTAssertTrue([[enumerator description] hasSuffix:@", string=\"aaabbbccc\" }"]); + enumerator = [regex segmentEnumeratorForString:@"aaabbbcccdddeeefffggghhh"]; + XCTAssertNotNil(enumerator); + XCTAssertTrue([[enumerator description] hasSuffix:@", string=\"aaabbbcccdddeeefffgg...\" }"]); + // regex w/ other options regex = [GTMRegex regexWithPattern:@"a+" options:(kGTMRegexOptionIgnoreCase | kGTMRegexOptionSupressNewlineSupport)]; -- cgit v1.2.3