Rule Description Example KPI
core.DivideZero Check for division by zero void test(int z) { if (z == 0) int x = 1 / z; // warn } Robustness
core.NonNullParamChecker Check for null pointers passed as arguments to a function whose arguments are references or marked with the ‘nonnull’ attribute int f(int *p) __attribute__((nonnull)); void test(int *p) { if (!p) f(p); // warn } Robustness
core.NullDereference Check for dereferences of null pointers void test(int *p) { if (p) return; int x = p[0]; // warn } Robustness
nullability.NullableDereferenced Warns when a nullable pointer is dereferenced. struct LinkedList { int data; struct LinkedList *next; }; struct LinkedList * _Nullable getNext(struct LinkedList *l); void updateNextData(struct LinkedList *list, int newData) { struct LinkedList *next = getNext(list); // Warning: Nullable pointer is dereferenced next->data = 7; } Robustness
nullability.NullablePassedToNonnull Warns when a nullable pointer is passed to a pointer which has a _Nonnull type. typedef struct Dummy { int val; } Dummy; Dummy *_Nullable returnsNullable(); void takesNonnull(Dummy *_Nonnull); void test() { Dummy *p = returnsNullable(); takesNonnull(p); // warn } Robustness
nullability.NullableReturnedFromNonnull Warns when a nullable pointer is returned from a function that has _Nonnull return type.   Robustness
nullability.NullPassedToNonnull Warns when a null pointer is passed to a pointer which has a _Nonnull type. if (name != nil) return; // Warning: nil passed to a callee that requires a non-null 1st parameter NSString *greeting = [@”Hello ” stringByAppendingString:name]; Robustness
nullability.NullReturnedFromNonnull Warns when a null pointer is returned from a function that has _Nonnull return type. – (nonnull id)firstChild { id result = nil; if ([_children count] > 0) result = _children[0]; // Warning: nil returned from a method that is expected // to return a non-null value return result; } Robustness
osx.cocoa.AtSync Check for nil pointers used as mutexes for @synchronized void test(id x) { if (!x) @synchronized(x) {} // warn: nil value used as mutex } Robustness
osx.cocoa.Dealloc Warn about Objective-C classes that lack a correct implementation of -dealloc @interface MyObject : NSObject { id _myproperty; } @end @implementation MyObject // warn: lacks ‘dealloc’ Robustness
osx.cocoa.IncompatibleMethodTypes Warn about Objective-C method signatures with type incompatibilities @interface MyClass1 : NSObject – (int)foo; @end @implementation MyClass1 – (int)foo { return 1; } @end @interface MyClass2 : MyClass1 – (float)foo; @end @implementation MyClass2 – (float)foo { return 1.0; } // warn @end Robustness
osx.cocoa.NilArg Check for prohibited nil arguments to ObjC method calls NSComparisonResult test(NSString *s) { NSString *aString = nil; return [s caseInsensitiveCompare:aString]; // warn: argument to ‘NSString’ method // ‘caseInsensitiveCompare:’ cannot be nil } Robustness
osx.cocoa.RetainCount Check for leaks and improper reference count management void test() { NSString *s = [[NSString alloc] init]; // warn } Resource Utilization
osx.cocoa.SelfInit Check that ‘self’ is properly initialized inside an initializer method @interface MyObj : NSObject { id x; } – (id)init; @end @implementation MyObj – (id)init { [super init]; x = 0; // warn: instance variable used while ‘self’ is not // initialized return 0; } @end Robustness
osx.cocoa.SuperDealloc Warn about improper use of ‘[super dealloc]’ in Objective-C @interface SuperDeallocThenReleaseIvarClass : NSObject { NSObject *_ivar; } @end @implementation SuperDeallocThenReleaseIvarClass – (void)dealloc { [super dealloc]; [_ivar release]; // warn } @end Resource Utilization
osx.cocoa.VariadicMethodTypes Check for passing non-Objective-C types to variadic collection initialization methods that expect only Objective-C types void test() { [NSSet setWithObjects:@”Foo”, “Bar”, nil]; // warn: argument should be an ObjC pointer type, not ‘char *’ } Robustness
osx.NumberObjectConversion Check for erroneous conversions of objects representing numbers into numbers NSNumber *photoCount = [albumDescriptor objectForKey:@”PhotoCount”]; // Warning: Comparing a pointer value of type ‘NSNumber *’ // to a scalar integer value if (photoCount > 0) { [self displayPhotos]; } Robustness
unix.MismatchedDeallocator Check for mismatched deallocators. // C, C++ void test() { int *p = (int *)malloc(sizeof(int)); delete p; // warn } Robustness