Index: www/analyzer/available_checks.html =================================================================== --- www/analyzer/available_checks.html +++ www/analyzer/available_checks.html @@ -2,187 +2,30 @@ "http://www.w3.org/TR/html4/strict.dtd"> - Available Checks + Available Checkers + - +
- -

Available Checks

- -

The list of the checks the analyzer performs by default

-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
core.AdjustedReturnValueCheck to see if the return value of a function call is different than the caller expects (e.g., from calls through function pointers).
core.CallAndMessageCheck for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers).
core.DivideZeroCheck for division by zero.
core.NonNullParamCheckerCheck for null pointers passed as arguments to a function whose arguments are known to be non-null.
core.NullDereferenceCheck for dereferences of null pointers.
core.StackAddressEscapeCheck that addresses to stack memory do not escape the function.
core.UndefinedBinaryOperatorResultCheck for undefined results of binary operators.
core.VLASizeCheck for declarations of VLA of undefined or zero size.
core.builtin.BuiltinFunctionsEvaluate compiler builtin functions (e.g., alloca()).
core.builtin.NoReturnFunctionsEvaluate "panic" functions that are known to not return to the caller.
core.uninitialized.ArraySubscriptCheck for uninitialized values used as array subscripts.
core.uninitialized.AssignCheck for assigning uninitialized values.
core.uninitialized.BranchCheck for uninitialized values used as branch conditions.
core.uninitialized.CapturedBlockVariableCheck for blocks that capture uninitialized values.
core.uninitialized.UndefReturnCheck for uninitialized values being returned to the caller.
cplusplus.NewDeleteCheck for double-free and use-after-free problems involving C++ delete.
deadcode.DeadStoresCheck for values stored to variables that are never read afterwards.
osx.APICheck for proper uses of various Apple APIs.
osx.SecKeychainAPICheck for proper uses of Secure Keychain APIs.
osx.cocoa.AtSyncCheck for nil pointers used as mutexes for @synchronized.
osx.cocoa.ClassReleaseCheck for sending 'retain', 'release', or 'autorelease' directly to a Class.
osx.cocoa.IncompatibleMethodTypesWarn about Objective-C method signatures with type incompatibilities.
osx.cocoa.NSAutoreleasePoolWarn for suboptimal uses of NSAutoreleasePool in Objective-C GC mode.
osx.cocoa.NSErrorCheck usage of NSError** parameters.
osx.cocoa.NilArgCheck for prohibited nil arguments to ObjC method calls.
osx.cocoa.RetainCountCheck for leaks and improper reference count management.
osx.cocoa.SelfInitCheck that 'self' is properly initialized inside an initializer method.
osx.cocoa.UnusedIvarsWarn about private ivars that are never used.
osx.cocoa.VariadicMethodTypesCheck for passing non-Objective-C types to variadic methods that expect only Objective-C types.
osx.coreFoundation.CFErrorCheck usage of CFErrorRef* parameters.
osx.coreFoundation.CFNumberCheck for proper uses of CFNumberCreate.
osx.coreFoundation.CFRetainReleaseCheck for null arguments to CFRetain/CFRelease/CFMakeCollectable.
osx.coreFoundation.containers.OutOfBoundsChecks for index out-of-bounds when using 'CFArray' API.
osx.coreFoundation.containers.PointerSizedValuesWarns if 'CFArray', 'CFDictionary', 'CFSet' are created with non-pointer-size values.
security.FloatLoopCounterWarn on using a floating point value as a loop counter (CERT: FLP30-C, FLP30-CPP).
security.insecureAPI.UncheckedReturnWarn on uses of functions whose return values must be always checked.
security.insecureAPI.getpwWarn on uses of the 'getpw' function.
security.insecureAPI.getsWarn on uses of the 'gets' function.
security.insecureAPI.mkstempWarn when 'mkstemp' is passed fewer than 6 X's in the format string.
security.insecureAPI.mktempWarn on uses of the 'mktemp' function.
security.insecureAPI.randWarn on uses of the 'rand', 'random', and related functions.
security.insecureAPI.strcpyWarn on uses of the 'strcpy' and 'strcat' functions.
security.insecureAPI.vforkWarn on uses of the 'vfork' function.
unix.APICheck calls to various UNIX/Posix functions.
unix.MallocCheck for memory leaks, double free, and use-after-free problems involving malloc.
unix.MallocSizeofCheck for dubious malloc arguments involving sizeof.
unix.MismatchedDeallocatorCheck for mismatched deallocators (e.g. passing a pointer allocating with new to free()).
unix.cstring.BadSizeArgCheck the size argument passed into C string functions for common erroneous patterns.
unix.cstring.NullArgCheck for null pointers being passed as arguments to C string functions.
- -

In addition to these the analyzer contains numerous experimental (alpha) checkers.

+

Available 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 +Default Checkers list below. In addition to +these, the analyzer contains a number of +Experimental (Alpha) Checkers.

Writeups with examples of some of the bugs that the analyzer finds

- +

Default Checkers

+ + + +

Core Checkers

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name, Description
Example
+ + +

C++ Checkers

+ + + + + + + + + + + + +
Name, Description
Example
+ + +

Dead Code Checkers

+ + + + + + + + + + + + +
Name, Description
Example
+ + +

OS X Checkers

+ + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name, Description
Example
+@interface Test : UIViewController
+@end
+@implementation test
+- (void)viewDidLoad {} // warn
+@end
+
+ + +

Security Checkers

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name, Description
Example
+ + +

Unix Checkers

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name, Description
Example
+int test() {
+  return strlen(0); // warn
+}
+
+ +
+
- Index: www/analyzer/checker_dev_manual.html =================================================================== --- www/analyzer/checker_dev_manual.html +++ www/analyzer/checker_dev_manual.html @@ -47,6 +47,7 @@
  • Testing
  • Useful Commands/Debugging Hints
  • Additional Sources of Information
  • +
  • Useful Links
  • Getting Started

    @@ -603,6 +604,11 @@ and video are available. + + + + Index: www/analyzer/content.css =================================================================== --- www/analyzer/content.css +++ www/analyzer/content.css @@ -38,7 +38,7 @@ #content { clear: left; - padding: 1em 2em 0 2em; + padding: 1em 2em 1em 2em; background-color: #ffffff; } @@ -54,9 +54,7 @@ text-align:left; border-top: 2px solid #cccccc; border-bottom: 2px solid #cccccc; - font-weight: bold; font-family: Verdana; - table-layout: fixed; - width: 100% + font-weight: bold; font-family: Verdana } table.options { border: 1px #cccccc solid } table.options { border-collapse: collapse; border-spacing: 0px } @@ -64,7 +62,6 @@ table.options td { border-bottom: 1px #cccccc dotted } table.options td { padding:5px; padding-left:8px; padding-right:8px } table.options td { text-align:left; font-size:9pt } -table.options col.option { width:207px } table.checkers { border: 1px #cccccc solid; @@ -76,28 +73,28 @@ word-wrap :break-word; font-size: 100%; } - table.checkers thead { background-color:#eee; color:#666666; border-top: 2px solid #cccccc; border-bottom: 2px solid #cccccc; font-weight: bold; font-family: Verdana; } - -table.checkers td { - padding:5px; padding-left:8px; padding-right:8px; - border-right: 1px #cccccc dotted; - border-bottom: 1px #cccccc dotted; -} - +table.checkers td { border-right: 1px #cccccc dotted; border-bottom: 1px #cccccc dotted; } table.checkers td.aligned { text-align: center; vertical-align: middle; } table.checkers col.namedescr { width: 45% } table.checkers col.example { width: 55% } table.checkers col.progress { width: 84px } -table.checkers pre { margin:1px; font-size: 100%; word-wrap :break-word; } -table.checkers .name { font-weight:bold; } -table.checkers .checked { background-color:#81F781; } -table.checkers .commented { color:#909090; } +table.checkers thead div.example, +table.checkers div.namedescr, +table.checkers div.exampleContainer { overflow: hidden; padding: 5px 8px 10px 8px } +/* table.checkers tbody div.example { font-family: monospace; white-space: pre } */ +table.checkers div.separator { border-top:1px #cccccc dashed; width:100%; margin: 5px 0px } +table.checkers span.name { font-weight: bold } +table.checkers span.lang { font-weight: bold; padding-left: 7px; /* display:block; */ } +table.checkers div.descr { margin-top:7px } +table.checkers div.functions { margin-top: 2px; font-style: italic; font-size: 90%; color:#00B } +table.checkers pre { margin: 1px; font-size: 100%; word-wrap: break-word } +table.checkers p { margin: 10px 0px 0px 0px; } /* Collapsing Trees: http://dbtree.megalingo.com/web/demo/simple-collapsible-tree.cfm */ #collapsetree, #collapsetree a:link, #collapsetree li a:link, #collapsetree a:visited, #collapsetree li a:visited{color:#000;text-decoration:none} Index: www/analyzer/potential_checkers.html =================================================================== --- www/analyzer/potential_checkers.html +++ www/analyzer/potential_checkers.html @@ -7,8 +7,9 @@ + - +
    @@ -21,120 +22,87 @@

    This page contains a list of potential checkers to implement in the static analyzer. If you are interested in contributing to the analyzer's development, this is a good resource to help you get started. The specific names of the checkers are subject to review, and are provided here as suggestions.

    -

    allocation/deallocation

    +

    memory

    - - - + - - - - - - + + + + + + + - + + +
    Name, DescriptionExampleProgress
    memory.LeakNeverReleased
    -(C, C++)


    -Memory may be never released, potential leak of memory -
    -
    -#include <stdlib.h>
    -
    -int f() {};
    -
    -void test() { 
    -  int *p1 = (int*)malloc(sizeof(int)); // warn
    -  int *p2 = new int; // warn
    -  int x = f();
    -  if (x==1)
    -    return;
    -  delete p2;
    -}
    -
    PR15237 -
    memory.MismatchedFree -
    enhancement to unix.Malloc
    (C, C++)


    -Mismatched deallocation function is used -
    -#include <stdlib.h>
    +
    PR15238 -
    memory.LeakPtrValChanged -
    enhancement to unix.Malloc
    (C, C++)


    -Potential memory leak: a pointer to newly allocated data loses its original -value -
    -#include <stdlib.h>
    -
    -void f(const int *);
    -void g(int *);
    +
    +
    +void f(int, int);
    +int g(int *);
    +int h() { throw 1; };
     
     void test() {
    -  int *p1 = new int;
    -  p1++; // warn
    -  int *p2 = (int *)malloc(sizeof(int));
    -  p2 = p1; // warn
    -  int *p3 = new int;
    -  f(p3);
    -  p3++; // warn
    -  int *p4 = new int;
    -  f(p4);
    -  p4++; // ok
    -}
    -
    done at r174678 (C case) -
    memory.LeakEvalOrder
    -(C, C++)


    -Potential memory leak: argument evaluation order is undefined, g() may never be called -
    -#include <stdlib.h>
    -
    -void f1(int, int);
    -void f2(int*, int*);
    -int g(int *) { throw 1; };
    -int h();
    -
    -void test() {
    -  f1(g(new int), h()); // warn
    -  f1(g((int *)malloc(sizeof(int))), h()); // warn
    -  f2(new int, new int);
    -}
    -
    memory.DstBufferTooSmall -
    (C, C++)


    -Destination buffer too small -
    -#include <string.h>
    -
    +  // It is possible that 'new int' is called first, 
    +  // then 'h()', that throws an exception and eventually 
    +  // 'g()' is never called.
    +  f(g(new int), h()); // warn: 'g()' may never be called.
    +}
    +
    memory.NegativeArraySize -
    enhancement to experimental.security.MallocOverflow
    (C, C++) -


    -'n' is used to specify the buffer size may be negative -
    -#include <stdlib.h>
     
    +
    @@ -144,42 +112,45 @@ Name, DescriptionExampleProgress -ctordtor.ExptInsideDtorExplicit
    -(C++)


    -It is dangerous to let an exception leave a destructor. Using try..catch will -solve the problem. -
    -void f();
    -
    +
    +
    + -ctordtor.PlacementSelfCopy
    -(C++11)


    -For a placement copy or move, it is almost certainly an error if the constructed object is also the object being copied from. -
    +
    +
    +
    + @@ -189,37 +160,55 @@ Name, DescriptionExampleProgress -valist.Uninitialized

    + + + +PR16811 + + + + +PR16812 @@ -229,34 +218,48 @@ Name, DescriptionExampleProgress -exceptions.ThrowSpecButNotThrow -
    (C++)


    -Function prototype has throw(T) specifier but the function do not throw -
    -void f() throw(int) { // warn
    -}
    -
    - -exceptions.NoThrowSpecButThrows -
    (C++)


    -An exception is throw from a function having the throw() specifier -
    -void f() throw() {
    +
    +
    +
    +
    +
    +
    +
    + + -exceptions.ThrownTypeDiffersSpec -
    (C++)


    -The type of a thrown exception differs from those specified in the throw(T) -specifier -
    +
    +
    + @@ -266,25 +269,36 @@ Name, DescriptionExampleProgress -smartptr.SmartPtrInit
    -(C++)


    -C++03: auto_ptr should store a pointer to an object obtained via new as allocated -memory will be cleaned using delete
    -C++11: one should use unique_ptr<T[]> to keep a pointer to memory -allocated by new[]
    -C++11: to keep a pointer to memory allocated by new[] in a shared_ptr one -should use a custom deleter that calls delete[] -
    +
    +
    +
    +#include <stdlib.h>
    +#include <memory>
    +
    +void test() {
    +  std::auto_ptr<int> p((int *)malloc(sizeof(int))); // warn
    +}
    +
    + @@ -294,40 +308,78 @@ Name, DescriptionExampleProgress -deadcode.UnmodifiedVariable -
    (C, C++)


    -A variable is never modified but was not declared const and is not a reference. -

    -(opt-in checker) -
    +
    +
    +PR16890 + + + +removed from alpha.deadcode.* at r198476 - +

    POSIX

    - + + +
    Name, DescriptionExampleProgress
    posix.Errno

    -Record that errno is non-zero when certain functions fail. -
    +
    PR18701
    PR18701
    @@ -348,11 +401,14 @@ Name, DescriptionExampleProgress -undefbehavior.ExitInDtor -
    (C++)


    -Undefined behavior: std::exit is called to end the program during the -destruction of an object with static storage duration -
    +
    +
    +
     
    -A a;
    -
    -undefbehavior.LocalStaticDestroyed -
    (C++)


    + + + - -undefbehavior.ZeroAllocDereference -
    enhancement to unix.Malloc
    (C, C++)


    + + + + -undefbehavior.DeadReferenced -
    (C++)


    + + + + -undefbehavior.ObjLocChanges -
    (C++)


    + + + + + + + + -undefbehavior.StaticInitReentered -
    (C)


    + + + + -undefbehavior.ConstModified -
    (C, C++)


    -Undefined behavior: const object is being modified -
    -#include <stdlib.h>
     
    -class X {
    -public :
    -  mutable int i;
    -  int j;
    -};
    -class Y {
    +
    +
    + + -undefbehavior.DeadDestructed -
    (C++)


    + + + -undefbehavior.MethodCallBeforeBaseInit -
    (C++)


    -Undefined behavior: calls member function but base not yet initialized -
    +
    +
    +
    + + -undefbehavior.MemberOrBaseRefBeforeCtor -
    (C++)


    + + + + -undefbehavior.MemberRefAfterDtor -
    (C++)


    + + + -// C++11 -struct S { - ~S() {}; - void f() {}; -}; -void test() { - S *s = new S(); - s->~S(); - s->f(); // warn -} - - -undefbehavior.CtorForeignCall -
    (C++)


    + + + -undefbehavior.CtorForeignCast -undefbehavior.CtorForeignTypeid -
    (C++)


    -Undefined behavior: the operand of typeid/dynamic_cast is an object under + + + + + + + + + + -undefbehavior.MemberRefInCatch -undefbehavior.BaseRefInCatch -
    (C++)


    + + + + + + + + + -undefbehavior.AutoptrsOwnSameObj -
    (C++03)


    -Undefined behavior: if more than one auto_ptr owns the same object at the same -time the behavior of the program is undefined. -
    +
    +
    + + + + + + -undefbehavior.EosDereference -
    (C++)


    -Undefined behavior: the result of operator*() on an end of stream is -undefined -
    +
    +
    +
    + -undefbehavior.QsortNonPOD -undefbehavior.QsortNonTrivial -
    C++


    + + + + + -undefbehavior.ThrowWhileCopy -
    C++


    + + + -undefbehavior.ValarrayArgBound -
    (C++)


    -Undefined behavior: the value of the second argument is greater than the number -of values pointed to by the first argument -
    +
    +
    +
    + + -undefbehavior.ValarrayLengthDiffer -
    (C++)


    -Undefined behavior: valarray operands are of different length -
    +
    +
    + + -undefbehavior.ValarrayZeroLength -
    (C++)


    -Undefined behavior: calling sum()/min()/max() method of an array having zero -length, the behavior is undefined -
    +
    +
    + -undefbehavior.ValarrayBadIndirection -
    (C++)


    -Undefined behavior: element N is specified more than once in the -indirection -
    +
    +
    +
    + + -undefbehavior.IosBaseDestroyedBeforeInit -
    (C++)

    -
    Undefined behavior: ios_base object is destroyed before initialization have -taken place. basic_ios::init should be call to initialize ios_base -members -
    +
    +
    + + -undefbehavior.IosBaseUsedBeforeInit -
    (C++11)


    -Undefined behavior: ios_base object is used before initialization have taken -place. basic_ios::init should be call to initialize ios_base members -
    +
    +
    + + -undefbehavior.MinusOnePosType -
    (C++)


    -Undefined behavior: passing -1 to any streambuf/istream/ostream member that -accepts a value of type traits::pos_type result in undefined behavior -
    +
    +
    + + @@ -1065,409 +1356,505 @@ Name, DescriptionExampleProgress -different.ArgEvalOrderUndef -
    (C)


    -Errors because of the order of evaluation of function arguments is undefined -
    -void f(int, int);
    -
    -void test() {
    -  int i = 0;
    -  int v[1] = {0};
    -  f(v[i], i++); // warn
    -}
    -
    - -different.FuncPtrInsteadOfCall -
    (C)


    -Possibly a function call should be used instead of a pointer to function -
    -int f();
    -
    -void test() {
    -  if (f == 0) {} // warn
    -}
    -
    - -SuccessiveAssign -
    (C)


    -Successive assign to a variable -
    -void test() { 
    -  int i=0;
    +
    +
    + + -different.NullDerefStmtOrder -
    enhancement to core.NullDereference
    (C)


    + + + + -different.NullDerefCondOrder -
    enhancement to core.NullDereference
    (C)


    + + + -different.MultipleAccessors -
    (C++)


    -multiple accessors met for 'class::field' -
    +
    +
    +
    + -different.AccessorsForPublic -
    (C++)


    -Accessors exist for 'class::field'. Should this field really be public? -
    +
    +
    +
    + + -different.LibFuncResultUnised -
    (C, C++)


    -Calling 'f' ignoring its return value is of no use (* create the list of known -system/library/API functions falling into this category) -
    +
    +
    + + -different.WrongVarForStmt -
    (C, C++)


    -Possibly wrong variable is used in the loop/cond-expression of the 'for' -statement. Did you mean 'proper_variable_name'? -
    +
    +
    + + -different.FloatingCompare -
    (C)


    -Comparing floating point numbers may be not precise -
    +
    +
    + -different.BoolCompare -
    maybe merge with experimental.core.BoolAssignment
    (C, C++)


    -Comparing boolean to a value other then 0 or 1 -
    -void test() {
    -  int i;
    -  if (0 < i < 3) {}; // warn
    -  bool b;
    -  if (b == 3) {}; // warn
    -}
    -
    -different.BitwiseOpBoolArg -
    maybe join with experimental.core.BoolAssignment
    (C, C++)


    -bool value is used at the left/right part of the & (|) operator. Did you mean -&& (||) ? -
    +
    +
    + -different.LabelInsideSwitch -
    (C)


    -Possible misprint: label found inside the switch() statement. (* did you mean -'default'?) -
    -void test() {
    -  int c = 7;
    +
    +
    +
    + -different.IdenticalCondIfIf -
    (C)


    -The conditions of two subsequent 'if' statements are identical -
    -void test() {
    -  int c = 7;
    -  if (c > 5) // <-
    +
    +
    +
    + -different.LogicalOpUselessArg -
    (C)


    -The second operand of the && operator has no impact on expression result -
    -void test() {
    -  unsigned a;
    +
    +
    +
    + -different.SameResLogicalExpr -
    (C)


    -The expression always evaluates to true/false -
    -void test() {
    -  int i=0;
    -  if (i!=0) {}; // warn
    -  if (i==0 && i==1) {}; // warn
    -  if (i<0 || i>=0) {}; // warn
    -}
    -
    - -different.SameResUnsignedCmp -
    (C)


    -Comparison of unsigned expression 'op expr' is always true/false -
    -void test() {
    -  unsigned u;
    -  if (u < -1) {}; // warn
    -  if (u >= 0) {}; // warn
    -}
    -
    - -different.OpPrecedenceAssignCmp -
    (C)


    -Comparison operation has higher precedence then assignment. Bool value is -assigned to variable of type 'type'. Parenthesis may bee required around an -assignment -
    -int f();
     
    +
    +
    +
    +
    +
    +
    +
    + + -different.OpPrecedenceIifShift -
    (C)


    -?: has lower precedence then << -
    +
    +
    +
    +void test(int a) {
    +  a << a > 7 ? 1 : 2; // warn
    +}
    +
    + -different.ObjectUnused -
    (C++)


    -The object was created but is not being used

    -The exception object was created but is not being used. Did you mean -'throw std::exception();'? -
    -#include <exception>
     
    +
    +
    +
     
    -  int a2[1][1];
    -  if (a2[0]) {}; // warn
    -}
    -
    -different.ConversionToBool -
    maybe join with experimental.core.BoolAssignment
    (C, C++)


    -Odd implicit conversion from 'type' to 'bool' -
    +
    +
    +
    +
    +
    +
    +
    + -different.ArrayBound -
    enhancement to experimental.security.ArrayBound[v2]
    (C, C++)


    -Out-of-bound dynamic array access -
    -#include <stdlib.h>
     
    +
    +
    + -different.StrcpyInputSize -
    enhancement to experimental.unix.cstring.OutOfBounds
    (C)


    -Buffer copy without checking size of input -
    +
    +
    +
    + + -different.IntegerOverflow -
    (C)


    -Integer overflow -
    +
    +
    + -different.SignExtension -
    (C)


    -Unexpected sign extension might take place -
    -void f(unsigned int i);
    -int g();
     
    -unsigned int test() {
    -  long long sll;
    +
    +
    +
    +unsigned int test(int i) {
    +  return i;
    +}
    +
    + -different.NumericTruncation -
    (C)


    -Numeric truncation might take place -
    -void f(int i);
    -int g();
     
    -int test() {
    -  unsigned long long ull;
    -  long long sll;
    +
    +
    +
    +int f();
     
    -different.MissingCopyCtorAssignOp
    -
    (C, C++)


    -The class has dynamically allocated data members but do not define a copy -constructor/assignment operator -
    -class C { // warn
    -  int *p; // <-
    +short test(long long sll) {
    +  short ss = f();
    +  return ss;
    +}
    +
    + + + + + + @@ -1477,57 +1864,73 @@ Name, DescriptionExampleProgress -WinAPI.CreateProcess -
    (C)


    -After calling CreateProcess(), ensure that process and thread handles get closed -(* for the given example: examine data flow from pi, pi.hProcess and pi.hThread) -
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + @@ -1537,25 +1940,30 @@ Name, DescriptionExampleProgress -optimization.PassConstObjByValue -
    (C, C++)


    -Optimization: It is more effective to pass const n-th parameter by reference to -avoid unnecessary object copying -
    -struct A {
    -  int a[20];
    -  int b;
    -};
    -
    -bool FirstIsZero(const struct A a) { // warn
    -  return a.a[0] == 0;
    -}
    -
    - -optimization.PostfixIncIter -
    (C++)


    -Optimization: It is more effective to use prefix ++ with iterator here -
    +
    +
    +
    +
    +
    +
    +
    + -optimization.MultipleCallsStrlen -
    (C)


    -Optimization: multiple calls to strlen for a given string in the given -expression. It is more effective to hold strlen result in a temporary -variable -
    +
    +
    +
    + -optimization.EmptyCstrDetect -
    (C)


    -Optimization: it is more efficient to use "str[0] != '\0'" to identify an empty -string -
    -#include <string.h>
     
    -void test() {
    -  const char* s = "abc";
    -  if (strlen(s) > 0) {}; // warn
    -}
    -
    - -optimization.StrLengthCalculation -
    (C, C++)


    -Optimization: it is more efficient to use string::length() method to calculate -string length -
    +
    +
    + -optimization.EmptyContainerDetect -
    (C, C++)


    -Optimization: It is more efficient to use container.empty() to identify an -empty container -
    +
    +
    +
    + +