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

[SR-95] CFStringCreateMutableCopy() string create broken copy #4206

Closed
krzyzanowskim opened this issue Dec 6, 2015 · 2 comments
Closed

[SR-95] CFStringCreateMutableCopy() string create broken copy #4206

krzyzanowskim opened this issue Dec 6, 2015 · 2 comments

Comments

@krzyzanowskim
Copy link
Contributor

Previous ID SR-95
Radar None
Original Reporter @krzyzanowskim
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 1
Component/s Foundation
Labels Bug, CoreFoundation
Assignee @phausler
Priority Medium

md5: dd84e00ecea160eade3b3808ece9fbb2

Issue Description:

```
let nstring: NSString = "абВГ"
let mCopy = CFStringCreateMutableCopy(kCFAllocatorSystemDefault, 0, nstring)
```
`mCopy._swiftObject` is now "аб".

CFStringCreateMutableCopy -> __CFStringReplace:
For NSString type: CFStringGetLength() relies on NSString.length (_storage.utf16.count) - this is 4 and __CFStrIsUnicode(str) is false - as a result only half string is copied.

This problem not exists in Xcode 7.1.1 (7B1005) that's why I think it is bug here.

ref: https://github.com/krzyzanowskim/swift-corelibs-foundation/commit/3039562d0ccae6f0f877df79aada27781c232646#commitcomment-14810527

@phausler
Copy link
Member

phausler commented Dec 9, 2015

__CFStrIsUnicode is no longer invoked on NSCFStrings in this code path, and it now queries the string for it's storage via _encodingCantBeStoredInEightBitCFString which should properly report the string to be абВГ in this case. It passes on both Mac OS X and Linux targets

@phausler
Copy link
Member

phausler commented Dec 9, 2015

verified by unit test pushed fb32aa @ github.com:apple/swift-corelibs-foundation.git

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants