This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
Avoid unsafe cast when removing style layers - #7227
Merged
Merged
Conversation
|
@boundsj, thanks for your PR! By analyzing this pull request, we identified @1ec5 and @jfirebaugh to be potential reviewers. |
jfirebaugh
approved these changes
Nov 29, 2016
1ec5
suggested changes
Nov 30, 2016
| of `MGLStyleLayer` and its subclasses. For private methods, an assertion is more appropriate. | ||
| */ | ||
| #define MGLAssertStyleLayerIsValid() \ | ||
| do { \ |
Contributor
There was a problem hiding this comment.
Please indent this macro so it’s more readable.
| if (!self.rawLayer) { \ | ||
| [NSException raise:@"Invalid style layer" \ | ||
| format: \ | ||
| @"-[%@ removeLayer:] has been called " \ |
Contributor
There was a problem hiding this comment.
The method is named -[MGLStyle removeLayer:], not -[MGL*StyleLayer removeLayer:].
1ec5
approved these changes
Nov 30, 2016
This updates the code generation for style layers to add a test to check that the style object returned from mbgl can be safely cast into the expected type so ownership can be returned to the caller when removing layers. This scenario was previously possible if a layer of type T was added before a layer of type U but both layers shared the same identifier. In that case, if the pointer to the second layer of type U was used to remove a layer, a runtime exception would occur since mbgl returns the layer with type T (the first one added). Now, an exception will still occur if layers with the same identifier are manipulated as described above but it is done as part of a validation check for all public style layer methods at the Darwin platform level. The NSException attempts to warn developers about using and reusing style identifiers to avoid this issue in the first place.
boundsj
force-pushed
the
boundsj-fix-style-cast
branch
from
November 30, 2016 17:16
6d886b7 to
3e8f944
Compare
Contributor
Author
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This updates the code generation for style layers to add a test to check that the style object returned from mbgl can be safely cast into the expected type so ownership can be returned to the caller when removing layers.
Previously a crash occurred if a layer of type T was added before a layer of type U but both layers shared the same identifier. In that case, if the pointer to the second layer of type U
was used to remove that layer, a runtime exception would occur since mbgl returns the layer with type T (the first one added) and the unsafe cast was triggered.
Now, even though the unsafe cast is avoided, an exception will still occur if layers with the same identifier are manipulated as described above but this is done as part of a validation check for all public style layer methods at the Darwin platform level. The raised
NSExceptionattempts to warn developers about reusing style identifiers to avoid this issue in the first place.Fixes #7211
cc @1ec5 @jfirebaugh