Index: www/analyzer/alpha_checks.html =================================================================== --- www/analyzer/alpha_checks.html +++ www/analyzer/alpha_checks.html @@ -24,6 +24,7 @@ Bug reports are welcome but will likely not be investigated for some time. Patches welcome!
Name, Description | Example |
+alpha.clone.CloneChecker
+(C, C++, ObjC)
+Reports similar pieces of code. |
+
+ +void log(); + +int max(int a, int b) { // warn + log(); + if (a > b) + return a; + return b; +} + +int maxClone(int x, int y) { // similar code here + log(); + if (x > y) + return x; + return y; +} + |
+alpha.core.CallAndMessageUnInitRefArg
+(C, C++)
+Check for uninitialized arguments in function calls and Objective-C
+message expressions. |
+
+ +void test(void) { + int t; + int &p = t; + int &s = p; + int &q = s; + foo(q); // warn +} + +void test(void) { + int x; + foo(&x); // warn +} + | ||||||
alpha.core.CastSize
(C)
Check when casting a malloc'ed type T, whether the size is a multiple of the
@@ -91,6 +146,47 @@
|
+
+alpha.core.Conversion
+(C, C++, ObjC)
+Loss of sign or precision in implicit conversions
+ +void test(unsigned U, signed S) { + if (S > 10) { + if (U < S) { + } + } + if (S < -10) { + if (U < S) { // warn (loss of sign) + } + } +} + +void test() { + long long A = 1LL << 60; + short X = A; // warn (loss of precision) +} + |
+
+alpha.core.DynamicTypeChecker
+(ObjC)
+Check for cases where the dynamic and the static type of an
+object are unrelated.
+ +id date = [NSDate date]; + +// Warning: Object has a dynamic type 'NSDate *' which is +// incompatible with static type 'NSNumber *'" +NSNumber *number = date; +[number doubleValue]; + |
@@ -178,6 +274,21 @@
}
alpha.core.FixedAddr
(C)
Check for assignment of a fixed address to a pointer. |
+
+alpha.core.TestAfterDivZero
+(C, C++, ObjC)
+Check for division by variable that is later compared against 0.
+Either the comparison is useless or there is division by zero.
+
+ +void test(int x) { + var = 77 / x; + if (x == 0) { } // warn +} + |
new
/
-delete
.-void test() { - int *p = new int; -} // warn -
-dealloc
.
--@interface MyObject : NSObject { - id _myproperty; -} -@end - -@implementation MyObject // warn: lacks 'dealloc' -@end -
-@interface MyObject : NSObject {} -@property(assign) id myproperty; -@end - -@implementation MyObject // warn: does not send 'dealloc' to super -- (void)dealloc { - self.myproperty = 0; -} -@end -
-@interface MyObject : NSObject { - id _myproperty; -} -@property(retain) id myproperty; -@end - -@implementation MyObject -@synthesize myproperty = _myproperty; - // warn: var was retained but wasn't released -- (void)dealloc { - [super dealloc]; -} -@end -
-@interface MyObject : NSObject { - id _myproperty; -} -@property(assign) id myproperty; -@end - -@implementation MyObject -@synthesize myproperty = _myproperty; - // warn: var wasn't retained but was released -- (void)dealloc { - [_myproperty release]; - [super dealloc]; -} -@end -
+NSString *reminderText = + NSLocalizedString(@"None", @"Indicates no reminders"); +if (reminderCount == 1) { + // Warning: Plural cases are not supported accross all languages. + // Use a .stringsdict file instead + reminderText = + NSLocalizedString(@"1 Reminder", @"Indicates single reminder"); +} else if (reminderCount >= 2) { + // Warning: Plural cases are not supported accross all languages. + // Use a .stringsdict file instead + reminderText = + [NSString stringWithFormat: + NSLocalizedString(@"%@ Reminders", @"Indicates multiple reminders"), + reminderCount]; +} +
-void __attribute((ownership_returns(malloc))) *my_malloc(size_t); - -void test() { - int *p = my_malloc(1); -} // warn: potential leak -
-void __attribute((ownership_returns(malloc))) *my_malloc(size_t); -void __attribute((ownership_takes(malloc, 1))) my_free(void *); - -void test() { - int *p = my_malloc(1); - my_free(p); - my_free(p); // warn: attempt to free released -} -
-void __attribute((ownership_returns(malloc))) *my_malloc(size_t); -void __attribute((ownership_holds(malloc, 1))) my_hold(void *); - -void test() { - int *p = my_malloc(1); - my_hold(p); - free(p); // warn: attempt to free non-owned memory -} -
-void __attribute((ownership_takes(malloc, 1))) my_free(void *); - -void test() { - int *p = malloc(1); - my_free(p); - *p = 1; // warn: use after free -} -
-void testBlockInCriticalSection() { - std::mutex m; - m.lock(); - sleep(3); // warn - m.unlock(); -} -
+cplusplus.NewDeleteLeaks
+(C++)
+Check for memory leaks. Traces memory managed by new /
+delete . |
+
+ +void test() { + int *p = new int; +} // warn + |
Name, Description | Example |
+nullability.NullPassedToNonnull
+(ObjC)
+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]; + |
+nullability.NullReturnedFromNonnull
+(ObjC)
+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; +} + |
+nullability.NullableDereferenced
+(ObjC)
+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; +} + |
+nullability.NullablePassedToNonnull
+(ObjC)
+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 +} + |
Name, Description | Example |
+optin.mpi.MPI-Checker
+(C)
+Checks MPI code |
+
+ +void test() { + double buf = 0; + MPI_Request sendReq1; + MPI_Ireduce(MPI_IN_PLACE, &buf, 1, MPI_DOUBLE, MPI_SUM, + 0, MPI_COMM_WORLD, &sendReq1); +} // warn: request 'sendReq1' has no matching wait. + +void test() { + double buf = 0; + MPI_Request sendReq; + MPI_Isend(&buf, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &sendReq); + MPI_Irecv(&buf, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &sendReq); // warn + MPI_Isend(&buf, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &sendReq); // warn + MPI_Wait(&sendReq, MPI_STATUS_IGNORE); +} + +void missingNonBlocking() { + int rank = 0; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Request sendReq1[10][10][10]; + MPI_Wait(&sendReq1[1][7][9], MPI_STATUS_IGNORE); // warn +} + |
+optin.osx.cocoa.localizability.EmptyLocalizationContextChecker
+(ObjC)
+Check that NSLocalizedString macros include a comment for context. |
+
+ +- (void)test { + NSString *string = NSLocalizedString(@"LocalizedString", nil); // warn + NSString *string2 = NSLocalizedString(@"LocalizedString", @" "); // warn + NSString *string3 = NSLocalizedStringWithDefaultValue( + @"LocalizedString", nil, [[NSBundle alloc] init], nil,@""); // warn +} + |
+optin.osx.cocoa.localizability.NonLocalizedStringChecker
+(ObjC)
+Warns about uses of non-localized NSStrings passed to UI methods
+expecting localized NSStrings |
+
+ +NSString *alarmText = + NSLocalizedString(@"Enabled", @"Indicates alarm is turned on"); +if (!isEnabled) { + alarmText = @"Disabled"; +} +UILabel *alarmStateLabel = [[UILabel alloc] init]; + +// Warning: User-facing text should use localized string macro +[alarmStateLabel setText:alarmText]; + |
+osx.NumberObjectConversion
+(C, C++, ObjC)
+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]; +} + | ||||||||
osx.SecKeychainAPI
(C)
Check for improper uses of the Security framework's Keychain APIs:
@@ -581,6 +765,66 @@
|
+
+osx.cocoa.Dealloc
+(ObjC)
+Warn about Objective-C classes that lack a correct implementation
+of -dealloc .
+
+ +@interface MyObject : NSObject { + id _myproperty; +} +@end + +@implementation MyObject // warn: lacks 'dealloc' +@end + +@interface MyObject : NSObject {} +@property(assign) id myproperty; +@end + +@implementation MyObject // warn: does not send 'dealloc' to super +- (void)dealloc { + self.myproperty = 0; +} +@end + +@interface MyObject : NSObject { + id _myproperty; +} +@property(retain) id myproperty; +@end + +@implementation MyObject +@synthesize myproperty = _myproperty; + // warn: var was retained but wasn't released +- (void)dealloc { + [super dealloc]; +} +@end + +@interface MyObject : NSObject { + id _myproperty; +} +@property(assign) id myproperty; +@end + +@implementation MyObject +@synthesize myproperty = _myproperty; + // warn: var wasn't retained but was released +- (void)dealloc { + [_myproperty release]; + [super dealloc]; +} +@end + |
@@ -688,6 +932,21 @@
osx.cocoa.IncompatibleMethodTypes
(ObjC)
Check for an incompatible type signature when overriding an Objective-C method. |
+
+osx.cocoa.ObjCGenerics
+(ObjC)
+Check for type errors when using Objective-C generics
+ +NSMutableArray |
@@ -742,6 +1001,26 @@
osx.cocoa.RetainCount
(ObjC)
Check for leaks and violations of the Cocoa Memory Management rules. |
+
+osx.cocoa.SuperDealloc
+(ObjC)
+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 + |
@@ -855,7 +1134,7 @@
osx.cocoa.UnusedIvars
(ObjC)
Warn about private ivars that are never used. |
+unix.Vfork
+(C)
+Check for proper usage of vfork |
+
+ +int test(int x) { + pid_t pid = vfork(); // warn + if (pid != 0) + return 0; + + switch (x) { + case 0: + pid = 1; + execl("", "", 0); + _exit(1); + break; + case 1: + x = 0; // warn: this assignment is prohibited + break; + case 2: + foo(); // warn: this function call is prohibited + break; + default: + return 0; // warn: return is prohibited + } + + while(1); +} + |
unix.cstring.BadSizeArg
(C)
Check the size argument passed to strncat for common erroneous
Index: www/analyzer/implicit_checks.html
===================================================================
--- www/analyzer/implicit_checks.html
+++ www/analyzer/implicit_checks.html
@@ -27,7 +27,7 @@
Core Implicit CheckersOS X Implicit Checkers |