r353711 - Fixed header underline in docs.
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 11 07:17:13 PST 2019
Author: alexfh
Date: Mon Feb 11 07:17:13 2019
New Revision: 353711
URL: http://llvm.org/viewvc/llvm-project?rev=353711&view=rev
Log:
Fixed header underline in docs.
+ Removed trailing whitespace.
Modified:
cfe/trunk/docs/analyzer/checkers.rst
Modified: cfe/trunk/docs/analyzer/checkers.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/analyzer/checkers.rst?rev=353711&r1=353710&r2=353711&view=diff
==============================================================================
--- cfe/trunk/docs/analyzer/checkers.rst (original)
+++ cfe/trunk/docs/analyzer/checkers.rst Mon Feb 11 07:17:13 2019
@@ -2,11 +2,11 @@
Available Checkers
==================
-The analyzer performs checks that are categorized into families or "checkers".
+The analyzer performs checks that are categorized into families or "checkers".
+
+The default set of checkers covers a variety of checks targeted at finding security and API usage bugs,
+dead code, and other logic errors. See the :ref:`default-checkers` checkers list below.
-The default set of checkers covers a variety of checks targeted at finding security and API usage bugs,
-dead code, and other logic errors. See the :ref:`default-checkers` checkers list below.
-
In addition to these, the analyzer contains a number of :ref:`alpha-checkers` (aka *alpha* checkers).
These checkers are under development and are switched off by default. They may crash or emit a higher number of false positives.
@@ -25,32 +25,32 @@ Default Checkers
core
^^^^
-Models core language features and contains general-purpose checkers such as division by zero,
-null pointer dereference, usage of uninitialized values, etc.
+Models core language features and contains general-purpose checkers such as division by zero,
+null pointer dereference, usage of uninitialized values, etc.
*These checkers must be always switched on as other checker rely on them.*
core.CallAndMessage (C, C++, ObjC)
""""""""""""""""""""""""""""""""""
Check for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers).
-.. literalinclude:: checkers/callandmessage_example.c
+.. literalinclude:: checkers/callandmessage_example.c
:language: objc
-
+
core.DivideZero (C, C++, ObjC)
""""""""""""""""""""""""""""""
Check for division by zero.
.. literalinclude:: checkers/dividezero_example.c
:language: c
-
-core.NonNullParamChecker (C, C++, ObjC)
+
+core.NonNullParamChecker (C, C++, ObjC)
"""""""""""""""""""""""""""""""""""""""
Check for null pointers passed as arguments to a function whose arguments are references or marked with the 'nonnull' attribute.
-.. code-block:: cpp
-
+.. code-block:: cpp
+
int f(int *p) __attribute__((nonnull));
-
+
void test(int *p) {
if (!p)
f(p); // warn
@@ -66,34 +66,34 @@ Check for dereferences of null pointers.
void test(int *p) {
if (p)
return;
-
+
int x = p[0]; // warn
}
-
+
// C
void test(int *p) {
if (!p)
*p = 0; // warn
}
-
+
// C++
class C {
public:
int x;
};
-
+
void test() {
C *pc = 0;
int k = pc->x; // warn
}
-
+
// Objective-C
@interface MyClass {
@public
int x;
}
@end
-
+
void test() {
MyClass *obj = 0;
obj->x = 1; // warn
@@ -106,16 +106,16 @@ Check that addresses to stack memory do
.. code-block:: c
char const *p;
-
+
void test() {
char const str[] = "string";
p = str; // warn
}
-
+
void* test() {
return __builtin_alloca(12); // warn
}
-
+
void test() {
static int *x;
int y;
@@ -134,19 +134,19 @@ Check for undefined results of binary op
int y = x + 1; // warn: left operand is garbage
}
-core.VLASize (C)
+core.VLASize (C)
""""""""""""""""
Check for declarations of Variable Length Arrays of undefined or zero size.
Check for declarations of VLA of undefined or zero size.
-
+
.. code-block:: c
void test() {
int x;
int vla1[x]; // warn: garbage as size
}
-
+
void test() {
int x = 0;
int vla2[x]; // warn: zero size
@@ -220,14 +220,14 @@ cplusplus.InnerPointer
""""""""""""""""""""""
Check for inner pointers of C++ containers used after re/deallocation.
-cplusplus.NewDelete (C++)
+cplusplus.NewDelete (C++)
"""""""""""""""""""""""""
Check for double-free and use-after-free problems. Traces memory managed by new/delete.
.. literalinclude:: checkers/newdelete_example.cpp
:language: cpp
-
-cplusplus.NewDeleteLeaks (C++)
+
+cplusplus.NewDeleteLeaks (C++)
""""""""""""""""""""""""""""""
Check for memory leaks. Traces memory managed by new/delete.
@@ -238,7 +238,7 @@ Check for memory leaks. Traces memory ma
} // warn
-cplusplus.SelfAssignment (C++)
+cplusplus.SelfAssignment (C++)
""""""""""""""""""""""""""""""
Checks C++ copy and move assignment operators for self assignment.
@@ -248,8 +248,8 @@ deadcode
^^^^^^^^
Dead Code Checkers.
-
-deadcode.DeadStores (C)
+
+deadcode.DeadStores (C)
"""""""""""""""""""""""
Check for values stored to variables that are never read afterwards.
@@ -278,7 +278,7 @@ Warns when a null pointer is passed to a
// Warning: nil passed to a callee that requires a non-null 1st parameter
NSString *greeting = [@"Hello " stringByAppendingString:name];
-nullability.NullReturnedFromNonnull (ObjC)
+nullability.NullReturnedFromNonnull (ObjC)
""""""""""""""""""""""""""""""""""""""""""
Warns when a null pointer is returned from a function that has _Nonnull return type.
@@ -288,7 +288,7 @@ Warns when a null pointer is returned fr
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;
@@ -299,14 +299,14 @@ nullability.NullableDereferenced (ObjC)
Warns when a nullable pointer is dereferenced.
.. code-block:: objc
-
+
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
@@ -318,17 +318,17 @@ nullability.NullablePassedToNonnull (Obj
Warns when a nullable pointer is passed to a pointer which has a _Nonnull type.
.. code-block:: objc
-
+
typedef struct Dummy { int val; } Dummy;
Dummy *_Nullable returnsNullable();
void takesNonnull(Dummy *_Nonnull);
-
+
void test() {
Dummy *p = returnsNullable();
takesNonnull(p); // warn
}
-nullability.NullableReturnedFromNonnull (ObjC)
+nullability.NullableReturnedFromNonnull (ObjC)
""""""""""""""""""""""""""""""""""""""""""""""
Warns when a nullable pointer is returned from a function that has _Nonnull return type.
@@ -352,7 +352,7 @@ Check virtual function calls during cons
}
virtual void f();
};
-
+
class A {
public:
~A() {
@@ -373,7 +373,7 @@ Checks MPI code.
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;
@@ -382,7 +382,7 @@ Checks MPI code.
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);
@@ -403,19 +403,19 @@ Check that NSLocalizedString macros incl
@"LocalizedString", nil, [[NSBundle alloc] init], nil,@""); // warn
}
-optin.osx.cocoa.localizability.NonLocalizedStringChecker (ObjC)
+optin.osx.cocoa.localizability.NonLocalizedStringChecker (ObjC)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Warns about uses of non-localized NSStrings passed to UI methods expecting localized NSStrings.
.. code-block:: objc
-
+
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];
@@ -439,22 +439,22 @@ security
Security related checkers.
-security.FloatLoopCounter (C)
+security.FloatLoopCounter (C)
"""""""""""""""""""""""""""""
Warn on using a floating point value as a loop counter (CERT: FLP30-C, FLP30-CPP).
.. code-block:: c
-
+
void test() {
for (float x = 0.1f; x <= 1.0f; x += 0.1f) {} // warn
}
-security.insecureAPI.UncheckedReturn (C)
+security.insecureAPI.UncheckedReturn (C)
""""""""""""""""""""""""""""""""""""""""
Warn on uses of functions whose return values must be always checked.
.. code-block:: c
-
+
void test() {
setuid(1); // warn
}
@@ -464,7 +464,7 @@ security.insecureAPI.bcmp (C)
Warn on uses of the 'bcmp' function.
.. code-block:: c
-
+
void test() {
bcmp(ptr0, ptr1, n); // warn
}
@@ -484,17 +484,17 @@ security.insecureAPI.bzero (C)
Warn on uses of the 'bzero' function.
.. code-block:: c
-
+
void test() {
bzero(ptr, n); // warn
}
-security.insecureAPI.getpw (C)
+security.insecureAPI.getpw (C)
""""""""""""""""""""""""""""""
Warn on uses of the 'getpw' function.
.. code-block:: c
-
+
void test() {
char buff[1024];
getpw(2, buff); // warn
@@ -505,7 +505,7 @@ security.insecureAPI.gets (C)
Warn on uses of the 'gets' function.
.. code-block:: c
-
+
void test() {
char buff[1024];
gets(buff); // warn
@@ -520,58 +520,58 @@ Warn when 'mkstemp' is passed fewer than
void test() {
mkstemp("XX"); // warn
}
-
-security.insecureAPI.mktemp (C)
+
+security.insecureAPI.mktemp (C)
"""""""""""""""""""""""""""""""
Warn on uses of the ``mktemp`` function.
.. code-block:: c
-
+
void test() {
char *x = mktemp("/tmp/zxcv"); // warn: insecure, use mkstemp
}
-security.insecureAPI.rand (C)
+security.insecureAPI.rand (C)
"""""""""""""""""""""""""""""
-Warn on uses of inferior random number generating functions (only if arc4random function is available):
+Warn on uses of inferior random number generating functions (only if arc4random function is available):
``drand48, erand48, jrand48, lcong48, lrand48, mrand48, nrand48, random, rand_r``.
.. code-block:: c
-
+
void test() {
random(); // warn
}
-
+
security.insecureAPI.strcpy (C)
"""""""""""""""""""""""""""""""
Warn on uses of the ``strcpy`` and ``strcat`` functions.
.. code-block:: c
-
+
void test() {
char x[4];
char *y = "abcd";
-
+
strcpy(x, y); // warn
}
-security.insecureAPI.vfork (C)
+security.insecureAPI.vfork (C)
""""""""""""""""""""""""""""""
Warn on uses of the 'vfork' function.
.. code-block:: c
-
+
void test() {
vfork(); // warn
}
-security.insecureAPI.DeprecatedOrUnsafeBufferHandling (C)
-""""""""""""""""""""""""""""""
+security.insecureAPI.DeprecatedOrUnsafeBufferHandling (C)
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Warn on occurrences of unsafe or deprecated buffer handling functions, which now have a secure variant: ``sprintf, vsprintf, scanf, wscanf, fscanf, fwscanf, vscanf, vwscanf, vfscanf, vfwscanf, sscanf, swscanf, vsscanf, vswscanf, swprintf, snprintf, vswprintf, vsnprintf, memcpy, memmove, strncpy, strncat, memset``
.. code-block:: c
-
+
void test() {
char buf [5];
strncpy(buf, "a", 1); // warn
@@ -583,26 +583,26 @@ unix
^^^^
POSIX/Unix checkers.
-unix.API (C)
+unix.API (C)
""""""""""""
Check calls to various UNIX/Posix functions: ``open, pthread_once, calloc, malloc, realloc, alloca``.
-.. literalinclude:: checkers/unix_api_example.c
+.. literalinclude:: checkers/unix_api_example.c
:language: c
-unix.Malloc (C)
+unix.Malloc (C)
"""""""""""""""
Check for memory leaks, double free, and use-after-free problems. Traces memory managed by malloc()/free().
-.. literalinclude:: checkers/unix_malloc_example.c
+.. literalinclude:: checkers/unix_malloc_example.c
:language: c
-
-unix.MallocSizeof (C)
+
+unix.MallocSizeof (C)
"""""""""""""""""""""
Check for dubious ``malloc`` arguments involving ``sizeof``.
.. code-block:: c
-
+
void test() {
long *p = malloc(sizeof(short));
// warn: result is converted to 'long *', which is
@@ -614,20 +614,20 @@ unix.MismatchedDeallocator (C, C++)
"""""""""""""""""""""""""""""""""""
Check for mismatched deallocators.
-.. literalinclude:: checkers/mismatched_deallocator_example.cpp
+.. literalinclude:: checkers/mismatched_deallocator_example.cpp
:language: c
-unix.Vfork (C)
+unix.Vfork (C)
""""""""""""""
Check for proper usage of ``vfork``.
.. code-block:: c
-
+
int test(int x) {
pid_t pid = vfork(); // warn
if (pid != 0)
return 0;
-
+
switch (x) {
case 0:
pid = 1;
@@ -643,25 +643,25 @@ Check for proper usage of ``vfork``.
default:
return 0; // warn: return is prohibited
}
-
+
while(1);
}
-unix.cstring.BadSizeArg (C)
+unix.cstring.BadSizeArg (C)
"""""""""""""""""""""""""""
-Check the size argument passed into C string functions for common erroneous patterns. Use ``-Wno-strncat-size`` compiler option to mute other ``strncat``-related compiler warnings.
+Check the size argument passed into C string functions for common erroneous patterns. Use ``-Wno-strncat-size`` compiler option to mute other ``strncat``-related compiler warnings.
.. code-block:: c
-
+
void test() {
char dest[3];
strncat(dest, """""""""""""""""""""""""*", sizeof(dest));
// warn: potential buffer overflow
}
-unix.cstrisng.NullArg (C)
+unix.cstrisng.NullArg (C)
"""""""""""""""""""""""""
-Check for null pointers being passed as arguments to C string functions:
+Check for null pointers being passed as arguments to C string functions:
``strlen, strnlen, strcpy, strncpy, strcat, strncat, strcmp, strncmp, strcasecmp, strncasecmp``.
.. code-block:: c
@@ -675,8 +675,8 @@ Check for null pointers being passed as
osx
^^^
OS X checkers.
-
-osx.API (C)
+
+osx.API (C)
"""""""""""
Check for proper uses of various Apple APIs.
@@ -692,7 +692,7 @@ osx.NumberObjectConversion (C, C++, ObjC
Check for erroneous conversions of objects representing numbers into numbers.
.. code-block:: objc
-
+
NSNumber *photoCount = [albumDescriptor objectForKey:@"PhotoCount"];
// Warning: Comparing a pointer value of type 'NSNumber *'
// to a scalar integer value
@@ -705,7 +705,7 @@ osx.ObjCProperty (ObjC)
Check for proper uses of Objective-C properties.
.. code-block:: objc
-
+
NSNumber *photoCount = [albumDescriptor objectForKey:@"PhotoCount"];
// Warning: Comparing a pointer value of type 'NSNumber *'
// to a scalar integer value
@@ -714,11 +714,11 @@ Check for proper uses of Objective-C pro
}
-osx.SecKeychainAPI (C)
+osx.SecKeychainAPI (C)
""""""""""""""""""""""
Check for proper uses of Secure Keychain APIs.
-.. literalinclude:: checkers/seckeychainapi_example.m
+.. literalinclude:: checkers/seckeychainapi_example.m
:language: objc
osx.cocoa.AtSync (ObjC)
@@ -731,14 +731,14 @@ Check for nil pointers used as mutexes f
if (!x)
@synchronized(x) {} // warn: nil value used as mutex
}
-
+
void test() {
id y;
@synchronized(y) {} // warn: uninitialized value used as mutex
}
osx.cocoa.AutoreleaseWrite
-""""""""""""""""""""""""""
+""""""""""""""""""""""""""
Warn about potentially crashing writes to autoreleasing objects from different autoreleasing pools in Objective-C.
osx.cocoa.ClassRelease (ObjC)
@@ -746,10 +746,10 @@ osx.cocoa.ClassRelease (ObjC)
Check for sending 'retain', 'release', or 'autorelease' directly to a Class.
.. code-block:: objc
-
+
@interface MyClass : NSObject
@end
-
+
void test(void) {
[MyClass release]; // warn
}
@@ -758,27 +758,27 @@ osx.cocoa.Dealloc (ObjC)
""""""""""""""""""""""""
Warn about Objective-C classes that lack a correct implementation of -dealloc
-.. literalinclude:: checkers/dealloc_example.m
+.. literalinclude:: checkers/dealloc_example.m
:language: objc
-osx.cocoa.IncompatibleMethodTypes (ObjC)
+osx.cocoa.IncompatibleMethodTypes (ObjC)
""""""""""""""""""""""""""""""""""""""""
Warn about Objective-C method signatures with type incompatibilities.
.. code-block:: objc
-
+
@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
@@ -810,8 +810,8 @@ Warn for suboptimal uses of NSAutoreleas
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[pool release]; // warn
}
-
-osx.cocoa.NSError (ObjC)
+
+osx.cocoa.NSError (ObjC)
""""""""""""""""""""""""
Check usage of NSError parameters.
@@ -820,18 +820,18 @@ Check usage of NSError parameters.
@interface A : NSObject
- (void)foo:(NSError """""""""""""""""""""""")error;
@end
-
+
@implementation A
- (void)foo:(NSError """""""""""""""""""""""")error {
// warn: method accepting NSError"""""""""""""""""""""""" should have a non-void
// return value
}
@end
-
+
@interface A : NSObject
- (BOOL)foo:(NSError """""""""""""""""""""""")error;
@end
-
+
@implementation A
- (BOOL)foo:(NSError """""""""""""""""""""""")error {
*error = 0; // warn: potential null dereference
@@ -839,7 +839,7 @@ Check usage of NSError parameters.
}
@end
-osx.cocoa.NilArg (ObjC)
+osx.cocoa.NilArg (ObjC)
"""""""""""""""""""""""
Check for prohibited nil arguments to ObjC method calls.
@@ -848,37 +848,37 @@ Check for prohibited nil arguments to Ob
- compare:options:
- compare:options:range:
- compare:options:range:locale:
- - componentsSeparatedByCharactersInSet:
+ - componentsSeparatedByCharactersInSet:
- initWithFormat:
.. code-block:: objc
-
+
NSComparisonResult test(NSString *s) {
NSString *aString = nil;
return [s caseInsensitiveCompare:aString];
// warn: argument to 'NSString' method
// 'caseInsensitiveCompare:' cannot be nil
}
-
+
osx.cocoa.NonNilReturnValue
"""""""""""""""""""""""""""
Models the APIs that are guaranteed to return a non-nil value.
-osx.cocoa.ObjCGenerics (ObjC)
+osx.cocoa.ObjCGenerics (ObjC)
"""""""""""""""""""""""""""""
Check for type errors when using Objective-C generics.
.. code-block:: objc
-
+
NSMutableArray *names = [NSMutableArray array];
NSMutableArray *birthDates = names;
-
+
// Warning: Conversion from value of type 'NSDate *'
// to incompatible type 'NSString *'
[birthDates addObject: [NSDate date]];
-osx.cocoa.RetainCount (ObjC)
+osx.cocoa.RetainCount (ObjC)
""""""""""""""""""""""""""""
Check for leaks and improper reference count management
@@ -887,7 +887,7 @@ Check for leaks and improper reference c
void test() {
NSString *s = [[NSString alloc] init]; // warn
}
-
+
CFStringRef test(char *bytes) {
return CFStringCreateWithCStringNoCopy(
0, bytes, NSNEXTSTEPStringEncoding, 0); // warn
@@ -903,13 +903,13 @@ osx.cocoa.SelfInit (ObjC)
Check that 'self' is properly initialized inside an initializer method.
.. code-block:: objc
-
+
@interface MyObj : NSObject {
id x;
}
- (id)init;
@end
-
+
@implementation MyObj
- (id)init {
[super init];
@@ -918,11 +918,11 @@ Check that 'self' is properly initialize
return 0;
}
@end
-
+
@interface MyObj : NSObject
- (id)init;
@end
-
+
@implementation MyObj
- (id)init {
[super init];
@@ -930,12 +930,12 @@ Check that 'self' is properly initialize
}
@end
-osx.cocoa.SuperDealloc (ObjC)
+osx.cocoa.SuperDealloc (ObjC)
"""""""""""""""""""""""""""""
Warn about improper use of '[super dealloc]' in Objective-C.
.. code-block:: objc
-
+
@interface SuperDeallocThenReleaseIvarClass : NSObject {
NSObject *_ivar;
}
@@ -947,7 +947,7 @@ Warn about improper use of '[super deall
[_ivar release]; // warn
}
@end
-
+
osx.cocoa.UnusedIvars (ObjC)
""""""""""""""""""""""""""""
Warn about private ivars that are never used.
@@ -959,39 +959,39 @@ Warn about private ivars that are never
id x; // warn
}
@end
-
+
@implementation MyObj
@end
osx.cocoa.VariadicMethodTypes (ObjC)
""""""""""""""""""""""""""""""""""""
-Check for passing non-Objective-C types to variadic collection
+Check for passing non-Objective-C types to variadic collection
initialization methods that expect only Objective-C types.
.. code-block:: objc
-
+
void test() {
[NSSet setWithObjects:@"Foo", "Bar", nil];
// warn: argument should be an ObjC pointer type, not 'char *'
}
-osx.coreFoundation.CFError (C)
+osx.coreFoundation.CFError (C)
""""""""""""""""""""""""""""""
Check usage of CFErrorRef* parameters
.. code-block:: c
-
+
void test(CFErrorRef *error) {
// warn: function accepting CFErrorRef* should have a
// non-void return
}
-
+
int foo(CFErrorRef *error) {
*error = 0; // warn: potential null dereference
return 0;
}
-osx.coreFoundation.CFNumber (C)
+osx.coreFoundation.CFNumber (C)
"""""""""""""""""""""""""""""""
Check for proper uses of CFNumber APIs.
@@ -1002,7 +1002,7 @@ Check for proper uses of CFNumber APIs.
// warn: 8 bit integer is used to initialize a 16 bit integer
}
-osx.coreFoundation.CFRetainRelease (C)
+osx.coreFoundation.CFRetainRelease (C)
""""""""""""""""""""""""""""""""""""""
Check for null arguments to CFRetain/CFRelease/CFMakeCollectable.
@@ -1012,15 +1012,15 @@ Check for null arguments to CFRetain/CFR
if (!p)
CFRetain(p); // warn
}
-
+
void test(int x, CFTypeRef p) {
if (p)
return;
-
+
CFRelease(p); // warn
}
-osx.coreFoundation.containers.OutOfBounds (C)
+osx.coreFoundation.containers.OutOfBounds (C)
"""""""""""""""""""""""""""""""""""""""""""""
Checks for index out-of-bounds when using 'CFArray' API.
@@ -1031,12 +1031,12 @@ Checks for index out-of-bounds when usin
CFArrayGetValueAtIndex(A, 0); // warn
}
-osx.coreFoundation.containers.PointerSizedValues (C)
+osx.coreFoundation.containers.PointerSizedValues (C)
""""""""""""""""""""""""""""""""""""""""""""""""""""
Warns if 'CFArray', 'CFDictionary', 'CFSet' are created with non-pointer-size values.
.. code-block:: c
-
+
void test() {
int x[] = { 1 };
CFArrayRef A = CFArrayCreate(0, (const void """""""""""""""""""""""")x, 1,
@@ -1054,21 +1054,21 @@ Experimental Checkers
alpha.clone
^^^^^^^^^^^
-alpha.clone.CloneChecker (C, C++, ObjC)
+alpha.clone.CloneChecker (C, C++, ObjC)
"""""""""""""""""""""""""""""""""""""""
Reports similar pieces of code.
.. code-block:: c
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)
@@ -1081,17 +1081,17 @@ alpha.core.BoolAssignment (ObjC)
Warn about assigning non-{0,1} values to boolean variables.
.. code-block:: objc
-
+
void test() {
BOOL b = -1; // warn
- }
+ }
alpha.core
^^^^^^^^^^
alpha.core.CallAndMessageUnInitRefArg (C,C++, ObjC)
"""""""""""""""""""""""""""""""""""""""""""""""""""
-Check for logical errors for function calls and Objective-C
+Check for logical errors for function calls and Objective-C
message expressions (e.g., uninitialized arguments, null function pointers, and pointer to undefined variables).
.. code-block:: c
@@ -1103,7 +1103,7 @@ message expressions (e.g., uninitialized
int &q = s;
foo(q); // warn
}
-
+
void test(void) {
int x;
foo(&x); // warn
@@ -1114,27 +1114,27 @@ alpha.core.CastSize (C)
Check when casting a malloc'ed type ``T``, whether the size is a multiple of the size of ``T``.
.. code-block:: c
-
+
void test() {
int *x = (int *) malloc(11); // warn
}
alpha.core.CastToStruct (C, C++)
-""""""""""""""""""""""""""""""""
+""""""""""""""""""""""""""""""""
Check for cast from non-struct pointer to struct pointer.
.. code-block:: cpp
-
+
// C
struct s {};
-
+
void test(int *p) {
struct s *ps = (struct s *) p; // warn
}
-
+
// C++
class c {};
-
+
void test(int *p) {
c *pc = (c *) p; // warn
}
@@ -1155,32 +1155,32 @@ Loss of sign/precision in implicit conve
}
}
}
-
+
void test() {
long long A = 1LL << 60;
short X = A; // warn (loss of precision)
}
-alpha.core.DynamicTypeChecker (ObjC)
+alpha.core.DynamicTypeChecker (ObjC)
""""""""""""""""""""""""""""""""""""
Check for cases where the dynamic and the static type of an object are unrelated.
.. code-block:: objc
-
+
id date = [NSDate date];
-
+
// Warning: Object has a dynamic type 'NSDate *' which is
// incompatible with static type 'NSNumber *'"
NSNumber *number = date;
[number doubleValue];
-alpha.core.FixedAddr (C)
+alpha.core.FixedAddr (C)
""""""""""""""""""""""""
Check for assignment of a fixed address to a pointer.
.. code-block:: c
-
+
void test() {
int *p;
p = (int *) 0x10000; // warn
@@ -1191,16 +1191,16 @@ alpha.core.IdenticalExpr (C, C++)
Warn about unintended use of identical expressions in operators.
.. code-block:: cpp
-
+
// C
void test() {
int a = 5;
int b = a | 4 | a; // warn: identical expr on both sides
}
-
+
// C++
bool f(void);
-
+
void test(bool b) {
int i = 10;
if (f()) { // warn: true and false branches are identical
@@ -1214,45 +1214,45 @@ Warn about unintended use of identical e
}
}
-alpha.core.PointerArithm (C)
+alpha.core.PointerArithm (C)
""""""""""""""""""""""""""""
Check for pointer arithmetic on locations other than array elements.
.. code-block:: c
-
+
void test() {
int x;
int *p;
p = &x + 1; // warn
}
-alpha.core.PointerSub (C)
+alpha.core.PointerSub (C)
"""""""""""""""""""""""""
Check for pointer subtractions on two pointers pointing to different memory chunks.
.. code-block:: c
-
+
void test() {
int x, y;
int d = &y - &x; // warn
}
-alpha.core.SizeofPtr (C)
+alpha.core.SizeofPtr (C)
""""""""""""""""""""""""
Warn about unintended use of ``sizeof()`` on pointer expressions.
.. code-block:: c
-
+
struct s {};
-
+
int test(struct s *p) {
return sizeof(p);
// warn: sizeof(ptr) can produce an unexpected result
}
-alpha.core.StackAddressAsyncEscape (C)
+alpha.core.StackAddressAsyncEscape (C)
""""""""""""""""""""""""""""""""""""""
-Check that addresses to stack memory do not escape the function that involves dispatch_after or dispatch_async.
+Check that addresses to stack memory do not escape the function that involves dispatch_after or dispatch_async.
This checker is a part of ``core.StackAddressEscape``, but is temporarily disabled until some false positives are fixed.
.. code-block:: c
@@ -1272,9 +1272,9 @@ This checker is a part of ``core.StackAd
// returned block
}
-alpha.core.TestAfterDivZero (C)
+alpha.core.TestAfterDivZero (C)
"""""""""""""""""""""""""""""""
-Check for division by variable that is later compared against 0.
+Check for division by variable that is later compared against 0.
Either the comparison is useless or there is division by zero.
.. code-block:: c
@@ -1287,39 +1287,39 @@ Either the comparison is useless or ther
alpha.cplusplus
^^^^^^^^^^^^^^^
-alpha.cplusplus.DeleteWithNonVirtualDtor (C++)
+alpha.cplusplus.DeleteWithNonVirtualDtor (C++)
""""""""""""""""""""""""""""""""""""""""""""""
Reports destructions of polymorphic objects with a non-virtual destructor in their base class.
.. code-block:: cpp
-
+
NonVirtual *create() {
NonVirtual *x = new NVDerived(); // note: conversion from derived to base
// happened here
return x;
}
-
+
void sink(NonVirtual *x) {
delete x; // warn: destruction of a polymorphic object with no virtual
// destructor
}
-alpha.cplusplus.EnumCastOutOfRange (C++)
+alpha.cplusplus.EnumCastOutOfRange (C++)
""""""""""""""""""""""""""""""""""""""""
-Check for integer to enumeration casts that could result in undefined values.
+Check for integer to enumeration casts that could result in undefined values.
.. code-block:: cpp
-
+
enum TestEnum {
A = 0
};
-
+
void foo() {
TestEnum t = static_cast(-1);
// warn: the value provided to the cast expression is not in
the valid range of values for the enum
-alpha.cplusplus.InvalidatedIterator (C++)
+alpha.cplusplus.InvalidatedIterator (C++)
"""""""""""""""""""""""""""""""""""""""""
Check for use of invalidated iterators.
@@ -1338,13 +1338,13 @@ alpha.cplusplus.IteratorRange (C++)
Check for iterators used outside their valid ranges.
.. code-block:: cpp
-
+
void simple_bad_end(const std::vector &v) {
auto i = v.end();
*i; // warn: iterator accessed outside of its range
}
-alpha.cplusplus.MismatchedIterator (C++)
+alpha.cplusplus.MismatchedIterator (C++)
""""""""""""""""""""""""""""""""""""""""
Check for use of iterators of different containers where iterators of the same container are expected.
@@ -1372,11 +1372,11 @@ Method calls on a moved-from object and
.. code-block:: cpp
-
+
struct A {
void foo() {}
};
-
+
void f() {
A a;
A b = std::move(a); // note: 'a' became 'moved-from' here
@@ -1386,10 +1386,10 @@ Method calls on a moved-from object and
alpha.cplusplus.UninitializedObject (C++)
"""""""""""""""""""""""""""""""""""""""""
-This checker reports uninitialized fields in objects created after a constructor call.
-It doesn't only find direct uninitialized fields, but rather makes a deep inspection
+This checker reports uninitialized fields in objects created after a constructor call.
+It doesn't only find direct uninitialized fields, but rather makes a deep inspection
of the object, analyzing all of it's fields subfields.
-The checker regards inherited fields as direct fields, so one will
+The checker regards inherited fields as direct fields, so one will
recieve warnings for uninitialized inherited data members as well.
.. code-block:: cpp
@@ -1441,7 +1441,7 @@ recieve warnings for uninitialized inher
A a(&b, &c); // no warning
}
- // With Pedantic set to true and
+ // With Pedantic set to true and
// CheckPointeeInitialization set to false
// (pointees are regarded as initialized)
@@ -1481,7 +1481,7 @@ This checker has several options which c
alpha.deadcode
^^^^^^^^^^^^^^
-alpha.deadcode.UnreachableCode (C, C++)
+alpha.deadcode.UnreachableCode (C, C++)
"""""""""""""""""""""""""""""""""""""""
Check unreachable code.
@@ -1493,18 +1493,18 @@ Check unreachable code.
while(x);
return x; // warn
}
-
+
// C++
void test() {
int a = 2;
-
+
while (a > 1)
a--;
-
+
if (a > 1)
a++; // warn
}
-
+
// Objective-C
void test(id x) {
return;
@@ -1532,21 +1532,21 @@ Check for direct assignments to instance
.. code-block:: objc
-
+
@interface MyClass : NSObject {}
@property (readonly) id A;
- (void) foo;
@end
-
+
@implementation MyClass
- (void) foo {
_A = 0; // warn
}
@end
-alpha.osx.cocoa.DirectIvarAssignmentForAnnotatedFunctions (ObjC)
+alpha.osx.cocoa.DirectIvarAssignmentForAnnotatedFunctions (ObjC)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
-Check for direct assignments to instance variables in
+Check for direct assignments to instance variables in
the methods annotated with ``objc_no_direct_instance_variable_assignment``.
.. code-block:: objc
@@ -1557,7 +1557,7 @@ the methods annotated with ``objc_no_dir
annotate("objc_no_direct_instance_variable_assignment")));
- (void) fNotAnnotated;
@end
-
+
@implementation MyClass
- (void) fAnnotated {
_A = 0; // warn
@@ -1570,7 +1570,7 @@ the methods annotated with ``objc_no_dir
alpha.osx.cocoa.InstanceVariableInvalidation (ObjC)
"""""""""""""""""""""""""""""""""""""""""""""""""""
-Check that the invalidatable instance variables are
+Check that the invalidatable instance variables are
invalidated in the methods annotated with objc_instance_variable_invalidator.
.. code-block:: objc
@@ -1579,16 +1579,16 @@ invalidated in the methods annotated wit
- (void) invalidate
__attribute__((annotate("objc_instance_variable_invalidator")));
@end
-
+
@interface InvalidationImpObj : NSObject <Invalidation>
@end
-
+
@interface SubclassInvalidationImpObj : InvalidationImpObj {
InvalidationImpObj *var;
}
- (void)invalidate;
@end
-
+
@implementation SubclassInvalidationImpObj
- (void) invalidate {}
@end
@@ -1604,19 +1604,19 @@ Check that the invalidation methods are
- (void)invalidate
__attribute__((annotate("objc_instance_variable_invalidator")));
@end
-
+
@interface NeedInvalidation : NSObject <Invalidation>
@end
-
+
@interface MissingInvalidationMethodDecl : NSObject {
NeedInvalidation *Var; // warn
}
@end
-
+
@implementation MissingInvalidationMethodDecl
@end
-alpha.osx.cocoa.localizability.PluralMisuseChecker (ObjC)
+alpha.osx.cocoa.localizability.PluralMisuseChecker (ObjC)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Warns against using one vs. many plural pattern in code when generating localized strings.
@@ -1640,21 +1640,21 @@ Warns against using one vs. many plural
alpha.security
^^^^^^^^^^^^^^
-alpha.security.ArrayBound (C)
+alpha.security.ArrayBound (C)
"""""""""""""""""""""""""""""
Warn about buffer overflows (older checker).
.. code-block:: c
-
+
void test() {
char *s = "";
char c = s[1]; // warn
}
-
+
struct seven_words {
int c[7];
};
-
+
void test() {
struct seven_words a, *p;
p = &a;
@@ -1662,45 +1662,45 @@ Warn about buffer overflows (older check
p[1] = a;
p[2] = a; // warn
}
-
+
// note: requires unix.Malloc or
// alpha.unix.MallocWithAnnotations checks enabled.
void test() {
int *p = malloc(12);
p[3] = 4; // warn
}
-
+
void test() {
char a[2];
int *b = (int*)a;
b[1] = 3; // warn
}
-
-alpha.security.ArrayBoundV2 (C)
+
+alpha.security.ArrayBoundV2 (C)
"""""""""""""""""""""""""""""""
Warn about buffer overflows (newer checker).
.. code-block:: c
-
+
void test() {
char *s = "";
char c = s[1]; // warn
}
-
+
void test() {
int buf[100];
int *p = buf;
p = p + 99;
p[1] = 1; // warn
}
-
+
// note: compiler has internal check for this.
// Use -Wno-array-bounds to suppress compiler warning.
void test() {
int buf[100][100];
buf[0][-1] = 1; // warn
}
-
+
// note: requires alpha.security.taint check turned on.
void test() {
char s[] = "abc";
@@ -1708,22 +1708,22 @@ Warn about buffer overflows (newer check
char c = s[x]; // warn: index is tainted
}
-alpha.security.MallocOverflow (C)
+alpha.security.MallocOverflow (C)
"""""""""""""""""""""""""""""""""
Check for overflows in the arguments to malloc().
.. code-block:: c
-
+
void test(int n) {
void *p = malloc(n * sizeof(int)); // warn
}
-alpha.security.MmapWriteExec (C)
+alpha.security.MmapWriteExec (C)
""""""""""""""""""""""""""""""""
Warn on mmap() calls that are both writable and executable.
.. code-block:: c
-
+
void test(int n) {
void *c = mmap(NULL, 32, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANON, -1, 0);
@@ -1739,39 +1739,39 @@ Check for an out-of-bound pointer being
.. code-block:: c
static int A[10];
-
+
int *test() {
int *p = A + 10;
return p; // warn
}
-
+
int test(void) {
int x;
return x; // warn: undefined or garbage returned
}
alpha.security.taint.TaintPropagation (C, C++)
-""""""""""""""""""""""""""""""""""""""""""""""
-Generate taint information used by other checkers.
+""""""""""""""""""""""""""""""""""""""""""""""
+Generate taint information used by other checkers.
A data is tainted when it comes from an unreliable source.
.. code-block:: c
-
+
void test() {
char x = getchar(); // 'x' marked as tainted
system(&x); // warn: untrusted data is passed to a system call
}
-
+
// note: compiler internally checks if the second param to
// sprintf is a string literal or not.
// Use -Wno-format-security to suppress compiler warning.
void test() {
char s[10], buf[10];
fscanf(stdin, "%s", s); // 's' marked as tainted
-
+
sprintf(buf, s); // warn: untrusted data as a format string
}
-
+
void test() {
size_t ts;
scanf("%zd", &ts); // 'ts' marked as tainted
@@ -1782,14 +1782,14 @@ A data is tainted when it comes from an
alpha.unix
^^^^^^^^^^^
-alpha.unix.BlockInCriticalSection (C)
+alpha.unix.BlockInCriticalSection (C)
"""""""""""""""""""""""""""""""""""""
-Check for calls to blocking functions inside a critical section.
+Check for calls to blocking functions inside a critical section.
Applies to: ``lock, unlock, sleep, getc, fgets, read, recv, pthread_mutex_lock,``
`` pthread_mutex_unlock, mtx_lock, mtx_timedlock, mtx_trylock, mtx_unlock, lock_guard, unique_lock``
.. code-block:: c
-
+
void test() {
std::mutex m;
m.lock();
@@ -1805,45 +1805,45 @@ Check improper use of chroot.
.. code-block:: c
void f();
-
+
void test() {
chroot("/usr/local");
f(); // warn: no call of chdir("/") immediately after chroot
}
-alpha.unix.PthreadLock (C)
+alpha.unix.PthreadLock (C)
""""""""""""""""""""""""""
Simple lock -> unlock checker.
Applies to: ``pthread_mutex_lock, pthread_rwlock_rdlock, pthread_rwlock_wrlock, lck_mtx_lock, lck_rw_lock_exclusive``
-``lck_rw_lock_shared, pthread_mutex_trylock, pthread_rwlock_tryrdlock, pthread_rwlock_tryrwlock, lck_mtx_try_lock,
+``lck_rw_lock_shared, pthread_mutex_trylock, pthread_rwlock_tryrdlock, pthread_rwlock_tryrwlock, lck_mtx_try_lock,
lck_rw_try_lock_exclusive, lck_rw_try_lock_shared, pthread_mutex_unlock, pthread_rwlock_unlock, lck_mtx_unlock, lck_rw_done``.
.. code-block:: c
-
+
pthread_mutex_t mtx;
-
+
void test() {
pthread_mutex_lock(&mtx);
pthread_mutex_lock(&mtx);
// warn: this lock has already been acquired
}
-
+
lck_mtx_t lck1, lck2;
-
+
void test() {
lck_mtx_lock(&lck1);
lck_mtx_lock(&lck2);
lck_mtx_unlock(&lck1);
// warn: this was not the most recently acquired lock
}
-
+
lck_mtx_t lck1, lck2;
-
+
void test() {
if (lck_mtx_try_lock(&lck1) == 0)
return;
-
+
lck_mtx_lock(&lck2);
lck_mtx_unlock(&lck1);
// warn: this was not the most recently acquired lock
@@ -1852,8 +1852,8 @@ lck_rw_try_lock_exclusive, lck_rw_try_lo
alpha.unix.SimpleStream (C)
"""""""""""""""""""""""""""
Check for misuses of stream APIs. Check for misuses of stream APIs: ``fopen, fclose``
-(demo checker, the subject of the demo (`Slides <http://llvm.org/devmtg/2012-11/Zaks-Rose-Checker24Hours.pdf>`_ ,
-`Video <https://youtu.be/kdxlsP5QVPw>`_) by Anna Zaks and Jordan Rose presented at the
+(demo checker, the subject of the demo (`Slides <http://llvm.org/devmtg/2012-11/Zaks-Rose-Checker24Hours.pdf>`_ ,
+`Video <https://youtu.be/kdxlsP5QVPw>`_) by Anna Zaks and Jordan Rose presented at the
`2012 LLVM Developers' Meeting <http://llvm.org/devmtg/2012-11/>`_).
.. code-block:: c
@@ -1861,13 +1861,13 @@ Check for misuses of stream APIs. Check
void test() {
FILE *F = fopen("myfile.txt", "w");
} // warn: opened file is never closed
-
+
void test() {
FILE *F = fopen("myfile.txt", "w");
-
+
if (F)
fclose(F);
-
+
fclose(F); // warn: closing a previously closed file stream
}
@@ -1881,29 +1881,29 @@ Check stream handling functions: ``fopen
void test() {
FILE *p = fopen("foo", "r");
} // warn: opened file is never closed
-
+
void test() {
FILE *p = fopen("foo", "r");
fseek(p, 1, SEEK_SET); // warn: stream pointer might be NULL
fclose(p);
}
-
+
void test() {
FILE *p = fopen("foo", "r");
-
+
if (p)
fseek(p, 1, 3);
// warn: third arg should be SEEK_SET, SEEK_END, or SEEK_CUR
-
+
fclose(p);
}
-
+
void test() {
FILE *p = fopen("foo", "r");
fclose(p);
fclose(p); // warn: already closed
}
-
+
void test() {
FILE *p = tmpfile();
ftell(p); // warn: stream pointer might be NULL
@@ -1927,7 +1927,7 @@ alpha.unix.cstring.NotNullTerminated (C)
Check for arguments which are not null-terminated strings; applies to: ``strlen, strnlen, strcpy, strncpy, strcat, strncat``.
.. code-block:: c
-
+
void test() {
int y = strlen((char *)&test); // warn
}
@@ -1938,7 +1938,7 @@ Check for out-of-bounds access in string
.. code-block:: c
-
+
void test() {
int y = strlen((char *)&test); // warn
}
More information about the cfe-commits
mailing list