Skip to content

Commit

Permalink
Address static analyzer warning in OCPartialMockObject
Browse files Browse the repository at this point in the history
* Issue #543 about potential nil passed to class_addMethod()

OCPartialMockObject#setupForwarderForSelector
* Modified to just return if there is no existing implementation for the method
  • Loading branch information
LowAmmo committed Nov 12, 2024
1 parent 7f6e9e9 commit c1fc8d0
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Source/OCMock/OCPartialMockObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c1fc8d0

Please sign in to comment.