Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fall back on CoreFoundation for some core NSString/NSCFString behaviours #671

Merged
merged 6 commits into from
Jul 21, 2016
14 changes: 13 additions & 1 deletion Frameworks/Foundation/NSString.mm
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,10 @@ - (BOOL)getBytes:(void*)buffer
@Status Interoperable
*/
- (void)getCharacters:(unichar*)dest range:(NSRange)range {
if (range.location + range.length > self.length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

surprised we didn't have this check already. use NSLocationInRange instead, though?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't exactly want that here; if length is 5, NSLocationInRange(5, {1,2}) will be false but that doesn't make this invalid.

[self _raiseBoundsExceptionForSelector:_cmd andRange:range];
}

for (unsigned int i = 0; i < range.length; i++) {
dest[i] = [self characterAtIndex:(i + range.location)];
}
Expand Down Expand Up @@ -1093,7 +1097,15 @@ - (NSRange)rangeOfString:(NSString*)searchString options:(NSStringCompareOptions
@Status Interoperable
*/
- (BOOL)isAbsolutePath {
return ([self hasPrefix:_NSGetSlashStr()]) || ((_isLetter([self characterAtIndex:0])) && ([self characterAtIndex:1] == ':'));
if ([self hasPrefix:_NSGetSlashStr()]) {
return YES;
}

if (self.length >= 2) {
return _isLetter([self characterAtIndex:0]) && [self characterAtIndex:1] == ':';
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is technically wrong, because C:Hello.txt is a relative path, not an absolute one.

Fixing it is out-of-scope for this change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked to DHowett offline, he's going to take a closer look at drive paths next iteration, and leave this slightly-wrong state for now.

Be sure to add a comment about this status.

}

return NO;
}

/**
Expand Down