SCAN-BUILD(1)

πŸ“¦ version 13.0.1, in debian bookworm, ubuntu jammy

πŸ’… SCAN-BUILD πŸ’…

okay so bestie, welcome to the scan-build page β€” that's the Clang static analyzer, and yes it lives in section 1 of your General Commands Manual. pull up a chair, grab a strawberry πŸ“, we're doing this.


✨ NAME ✨

scan-build β€” the Clang static analyzer, fr fr


✨ SYNOPSIS ✨

scan-build [-ohkvV] [-analyze-headers] [-enable-checker [checker_name]]
           [-disable-checker [checker_name]] [--help] [--help-checkers]
           [--html-title [=title]] [--keep-going] [-plist] [-plist-html]
           [--status-bugs] [--use-c++ [=compiler_path]]
           [--use-cc [=compiler_path]] [--view] [-constraints [model]]
           [-maxloop N] [-no-failure-reports] [-stats] [-store [model]]
           build_command [build_options]

✨ DESCRIPTION ✨

so scan-build is a Perl script that invokes the Clang static analyzer. that's the whole vibe. πŸ’…

the way it works: all the options meant for scan-build or for the analyzer come first, and then you hand it the build_command plus whatever build_options you'd normally use to build the target system. analyzer options, then build stuff. order matters, bestie.

the static analyzer runs a whole long list of checking algorithms β€” scroll down to CHECKERS for that. and the output? it can be written in standard .plist and/or HTML format. your call. 🌈

the following options are supported:


✨ OPTIONS ✨

  • -analyze-headers β€” also analyze functions inside #included files. going deep, no cap.
  • -enable-checker checker_name , -disable-checker checker_name β€” turn checker_name on or off. peek at CHECKERS for the roster. ✨
  • -h, --help β€” displays this message. hi, hello, that's the one you're reading.
  • --help-checkers β€” lists the default checkers. again, CHECKERS. πŸ‘‘
  • --html-title[=*title*] β€” sets the title used on the generated HTML pages. if you don't pass title, a default title gets generated for you. πŸŽ€
  • -k, --keep-going β€” adds a "keep on going" option to build_command. right now it supports make and xcodebuild. it's a convenience option, ngl β€” you could just set this behavior directly with build options if you wanted. your choice, main character.
  • -o β€” target directory for the HTML report files. subdirectories get created as needed to represent separate invocations of the analyzer. and if you don't specify this option? a directory gets created in /tmp (TMPDIR on Mac OS X) to store the reports. πŸ¦‹
  • -plist β€” outputs the results as a set of .plist files. (by default the output of scan-build is a set of HTML files, fyi.)
  • -plist-html β€” outputs the results as a set of HTML and .plist files. both. why not. πŸ’…
  • --status-bugs β€” sets the exit status to 1 if it found potential bugs, and 0 otherwise. by default the exit status of scan-build is whatever build_command returned. πŸ‘€
  • --use-c++[=*compiler_path*] β€” guesses the default compiler for your C++ and Objective-C++ code. use this option to specify an alternate compiler. 🧚
  • --use-cc[=*compiler_path*] β€” guesses the default compiler for your C and Objective-C code. use this option to specify an alternate compiler.
  • -v β€” verbose output from scan-build and the analyzer. a second and third v increases verbosity. v, vv, vvv β€” escalating. πŸ“ˆ
  • -V, --view β€” view the analysis results in a web browser when the build completes. cute lil report, in your browser. 🌸
  • -constraints [*model*] β€” specify the constraint engine used by the analyzer. by default the 'range' model is used. specifying 'basic' uses a simpler, less powerful constraint model β€” the one used by checker-0.160 and earlier.
  • -maxloop N β€” specify the number of times a block can be visited before giving up. default is 4. increase it for more comprehensive coverage, at a cost of speed. πŸƒβ™€οΈ
  • -no-failure-reports β€” do not create a 'failures' subdirectory that includes analyzer crash reports and preprocessed source files.
  • -stats β€” generates visitation statistics for the project being analyzed. πŸ“Š
  • -store [*model*] β€” specify the store model used by the analyzer. by default, the 'region' store model is used. 'region' specifies a field-sensitive store model. users can also specify 'basic', which is far less precise but can more quickly analyze code. 'basic' was the default store model for checker-0.221 and earlier.

✨ EXIT STATUS ✨

scan-build returns the value returned by build_command β€” unless --status-bugs or --keep-going is used. 😭 don't forget that part.


✨ CHECKERS ✨

all the checkers listed below can be enabled/disabled with the -enable-checker and -disable-checker options. a default group of checkers runs unless you explicitly disable them. exactly which checkers make up that default group is a function of the operating system you're on, bestie β€” and you can list them with --help-checkers. 🫢

  • core.AdjustedReturnValue β€” check to see if the return value of a function call is different than the caller expects (e.g., from calls through function pointers).
  • core.AttributeNonNull β€” check for null pointers passed as arguments to a function whose arguments are marked with the 'nonnull' attribute.
  • core.CallAndMessage β€” check for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers).
  • core.DivideZero β€” check for division by zero.
  • core.NullDereference β€” check for dereferences of null pointers. 😬
  • core.StackAddressEscape β€” check that addresses to stack memory do not escape the function.
  • core.UndefinedBinaryOperatorResult β€” check for undefined results of binary operators.
  • core.VLASize β€” check for declarations of VLA of undefined or zero size.
  • core.builtin.BuiltinFunctions β€” evaluate compiler builtin functions, e.g. alloca().
  • core.builtin.NoReturnFunctions β€” evaluate 'panic' functions that are known to not return to the caller.
  • core.uninitialized.ArraySubscript β€” check for uninitialized values used as array subscripts.
  • core.uninitialized.Assign β€” check for assigning uninitialized values.
  • core.uninitialized.Branch β€” check for uninitialized values used as branch conditions.
  • core.uninitialized.CapturedBlockVariable β€” check for blocks that capture uninitialized values.
  • core.uninitialized.UndefReturn β€” check for uninitialized values being returned to the caller.
  • deadcode.DeadStores β€” check for values stored to variables that are never read afterwards. rip to those writes.
  • debug.DumpCFG β€” display Control-Flow Graphs.
  • debug.DumpCallGraph β€” display Call Graph.
  • debug.DumpDominators β€” print the dominance tree for a given Control-Flow Graph.
  • debug.DumpLiveVars β€” print results of live variable analysis.
  • debug.Stats β€” emit warnings with analyzer statistics.
  • debug.TaintTest β€” mark tainted symbols as such. πŸ’€
  • debug.ViewCFG β€” view Control-Flow Graphs using GraphViz.
  • debug.ViewCallGraph β€” view Call Graph using GraphViz.
  • llvm.Conventions β€” check code for LLVM codebase conventions.
  • osx.API β€” check for proper uses of various Mac OS X APIs.
  • osx.AtomicCAS β€” evaluate calls to OSAtomic functions.
  • osx.SecKeychainAPI β€” check for proper uses of Secure Keychain APIs.
  • osx.cocoa.AtSync β€” check for null pointers used as mutexes for @synchronized.
  • osx.cocoa.ClassRelease β€” check for sending 'retain', 'release,' or 'autorelease' directly to a Class.
  • osx.cocoa.IncompatibleMethodTypes β€” warn about Objective-C method signatures with type incompatibilities.
  • osx.cocoa.NSAutoreleasePool β€” warn for suboptimal uses of NSAutoreleasePool in Objective-C GC mode.
  • osx.cocoa.NSError β€” check usage of NSError** parameters.
  • osx.cocoa.NilArg β€” check for prohibited nil arguments to Objective-C method calls.
  • osx.cocoa.RetainCount β€” check for leaks and improper reference count management.
  • osx.cocoa.SelfInit β€” check that 'self' is properly initialized inside an initializer method.
  • osx.cocoa.UnusedIvars β€” warn about private ivars that are never used.
  • osx.cocoa.VariadicMethodTypes β€” check for passing non-Objective-C types to variadic methods that expect only Objective-C types.
  • osx.coreFoundation.CFError β€” check usage of CFErrorRef* parameters.
  • osx.coreFoundation.CFNumber β€” check for proper uses of CFNumberCreate().
  • osx.coreFoundation.CFRetainRelease β€” check for null arguments to CFRetain(), CFRelease(), and CFMakeCollectable().
  • osx.coreFoundation.containers.OutOfBounds β€” checks for index out-of-bounds when using the CFArray API.
  • osx.coreFoundation.containers.PointerSizedValues β€” warns if CFArray, CFDictionary, or CFSet are created with non-pointer-size values.
  • security.FloatLoopCounter β€” warn on using a floating point value as a loop counter (CERT: FLP30-C, FLP30-CPP).
  • security.insecureAPI.UncheckedReturn β€” warn on uses of functions whose return values must be always checked.
  • security.insecureAPI.getpw β€” warn on uses of getpw().
  • security.insecureAPI.gets β€” warn on uses of gets().
  • security.insecureAPI.mkstemp β€” warn when mkstemp() is passed fewer than 6 X's in the format string.
  • security.insecureAPI.mktemp β€” warn on uses of mktemp().
  • security.insecureAPI.rand β€” warn on uses of rand(), random(), and related functions.
  • security.insecureAPI.strcpy β€” warn on uses of strcpy() and strcat().
  • security.insecureAPI.vfork β€” warn on uses of vfork().
  • unix.API β€” check calls to various UNIX/Posix functions.
  • unix.Malloc β€” check for memory leaks, double free, and use-after-free. the big three 😭
  • unix.cstring.BadSizeArg β€” check the size argument passed into C string functions for common erroneous patterns.
  • unix.cstring.NullArg β€” check for null pointers being passed as arguments to C string functions.

✨ EXAMPLE ✨

scan-build -o /tmp/myhtmldir make -j4

the example above makes the analysis reports land in a subdirectory of /tmp/myhtmldir, and runs make with the -j4 option. a different subdirectory gets created every single time scan-build analyzes a project. iconic behavior honestly.

the analyzer should support most parallel builds, but not distributed builds. know the limits, bestie. 🚫

✨ AUTHORS ✨

scan-build was written by Ted Kremenek. documentation contributed by James K. Lowden <jklowden@schemamania.org>.


and that's the whole page, babe πŸ’– this one shipped with clang 3.5, dated May 25, 2012 β€” old money, still eating. go analyze something. πŸ’…βœ¨

πŸ“¦ where this page comes from