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

OCMock: Fix crash when running on iOS 15 device. #13

Closed

Conversation

byohay
Copy link

@byohay byohay commented May 1, 2022

object_getClass crashes on some arguments when being run on an iOS 15
device. object_getClass is needed because OCMock needs to detect if
the argument is actually a OCMPassByRefSetter, which disguises as a
pointer to an object (id *) but is actually an object (id).
The solution is to make sure before calling object_getClass that the
type encoding of the argument is actually a pointer to an object, and
then it should be safe to call object_getClass.
The problem is that the value was previously wrapped with an NSValue,
which disguised the type encoding as a void *. Therefore the check of
whether the argument is id * is done before it will be wrapped with
NSValue.

`object_getClass` crashes on some arguments when being run on an iOS 15
device. `object_getClass` is needed because OCMock needs to detect if
the argument is actually a `OCMPassByRefSetter`, which disguises as a
pointer to an object (`id *`) but is actually an object (`id`).
The solution is to make sure before calling `object_getClass` that the
type encoding of the argument is actually a pointer to an object, and
then it should be safe to call `object_getClass`.
The problem is that the value was previously wrapped with an `NSValue`,
which disguised the type encoding as a `void *`. Therefore the check of
whether the argument is `id *` is done before it will be wrapped with
`NSValue`.
@byohay byohay changed the base branch from master to test-master May 1, 2022 07:16
@byohay byohay changed the title feature/fix ios 15 device crash OCMock: Fix crash when running on iOS 15 device. May 1, 2022
@byohay byohay marked this pull request as draft May 1, 2022 07:17
@byohay
Copy link
Author

byohay commented May 1, 2022

Replaced with a more robust solution: erikdoe#503

@byohay byohay closed this May 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants