CFPropertyList: fix CFPropertyListCreateDeepCopy of mutable containers#61
Open
DTW-Thalion wants to merge 1 commit into
Open
CFPropertyList: fix CFPropertyListCreateDeepCopy of mutable containers#61DTW-Thalion wants to merge 1 commit into
DTW-Thalion wants to merge 1 commit into
Conversation
Two bugs prevented CFPropertyListCreateDeepCopy from copying a mutable array or dictionary: * The type-ID table was never initialised on this path (CFPropertyListInitTypeIDs was only called from the validation code), so every CFGetTypeID comparison failed and the function returned NULL unless some other property-list call had already run. * The mutable array and dictionary branches applied their copy function over the freshly-created (empty) destination container instead of the source plist, so even with the type IDs initialised the result was empty. Call CFPropertyListInitTypeIDs at the top, and apply the copy functions over the source plist. Add Tests/CFPropertyList/deepcopy.m.
d91495c to
40f063b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CFPropertyListCreateDeepCopycould not deep-copy a mutable array ordictionary, for two reasons:
Type IDs never initialised on this path.
CFPropertyListInitTypeIDs(which lazily fills
_kCFArrayTypeID,_kCFDictionaryTypeID, …) was onlycalled from the validation code. On a standalone
CFPropertyListCreateDeepCopycall, every
CFGetTypeID(...) == _kCF*TypeIDcomparison saw0, no branchmatched, and the function returned NULL.
Copy applied over the empty destination. Once the type IDs are
initialised, the mutable array and dictionary branches applied their copy
function over the freshly-created (empty) destination container instead of
the source
plist:so the result came back empty (and iterating the empty array over
range (0, cnt)was itself out of range).Fix
Call
CFPropertyListInitTypeIDs()at the top, and apply the copy functionsover the source
plist.Test
Tests/CFPropertyList/deepcopy.m: deep-copying a mutable array and a mutabledictionary preserves their elements.