From d00d8f37a97e415c65617edf8521568dc41cb263 Mon Sep 17 00:00:00 2001 From: Erik Doernenburg Date: Sun, 4 Nov 2018 17:06:25 +0100 Subject: [PATCH] Fix for the UBSan issue reported in #362. --- Source/OCMock/OCPartialMockObject.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/OCMock/OCPartialMockObject.m b/Source/OCMock/OCPartialMockObject.m index 5f21eaa4..2aa81a49 100644 --- a/Source/OCMock/OCPartialMockObject.m +++ b/Source/OCMock/OCPartialMockObject.m @@ -174,9 +174,9 @@ - (void)setupForwarderForSelector:(SEL)sel return; Method originalMethod = class_getInstanceMethod(mockedClass, sel); - IMP originalIMP = method_getImplementation(originalMethod); - const char *types = method_getTypeEncoding(originalMethod); /* Might be NULL if the selector is forwarded to another class */ + IMP originalIMP = (originalMethod != NULL) ? method_getImplementation(originalMethod) : NULL; + const char *types = (originalMethod != NULL) ? method_getTypeEncoding(originalMethod) : NULL; // TODO: check the fallback implementation is actually sufficient if(types == NULL) types = ([[mockedClass instanceMethodSignatureForSelector:sel] fullObjCTypes]);