From c1fc8d01d21fe47886bb36b8577adbea084d5900 Mon Sep 17 00:00:00 2001 From: Kris Kline Date: Tue, 12 Nov 2024 15:40:06 -0600 Subject: [PATCH] Address static analyzer warning in OCPartialMockObject * Issue #543 about potential nil passed to class_addMethod() OCPartialMockObject#setupForwarderForSelector * Modified to just return if there is no existing implementation for the method --- Source/OCMock/OCPartialMockObject.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/OCMock/OCPartialMockObject.m b/Source/OCMock/OCPartialMockObject.m index 6a7c53c3..b3019e03 100644 --- a/Source/OCMock/OCPartialMockObject.m +++ b/Source/OCMock/OCPartialMockObject.m @@ -206,6 +206,9 @@ - (void)setupForwarderForSelector:(SEL)sel Method originalMethod = class_getInstanceMethod(mockedClass, sel); /* Might be NULL if the selector is forwarded to another class */ IMP originalIMP = (originalMethod != NULL) ? method_getImplementation(originalMethod) : NULL; + if(originalIMP == NULL) + return; + const char *types = (originalMethod != NULL) ? method_getTypeEncoding(originalMethod) : NULL; // TODO: check the fallback implementation is actually sufficient if(types == NULL)