SCAN-BUILD(1)

πŸ“¦ version 15.0.7, in debian bookworm, ubuntu jammy, ubuntu noble

✨ SCAN-BUILD ✨

okay so bestie, welcome to scan-build β€” the General Commands Manual entry, section 1, and yes it's the Clang static analyzer, and yes it's lowkey iconic. πŸ’…


πŸ’– NAME πŸ’–

scan-build β€” the Clang static analyzer πŸ¦‹


πŸŽ€ 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 🌸

scan-build is a Perl script that invokes the Clang static analyzer. fr fr that's the whole vibe. ✨

So here's the order of operations, bestie: the options used by scan-build or by the analyzer come first, and then after those you drop in the build_command and any build_options you'd normally use to build the target system. that's it, that's the layout 🫢

The static analyzer employs a long list of checking algorithms β€” go look at β€œCHECKERS” below, it's a whole journey. And your output? It can be written in standard .plist and/or HTML format. pick your fighter πŸ’…

The following options are supported:

  • -analyze-headers β€” also analyze functions in #included files. yes, even the headers. we go all the way in 🧚
  • -enable-checker checker_name, -disable-checker checker_name β€” enable/disable checker_name. peek at β€œCHECKERS” for the roster πŸ’œ
  • -h, --help β€” display this message. classic. πŸŽ€
  • --help-checkers β€” list default checkers, see β€œCHECKERS”. πŸ‘‘
  • --html-title[=*title*] β€” specify the title used on generated HTML pages. if title isn't specified, a default title is generated for you, no stress πŸ’–
  • -k, --keep-going β€” add a β€œkeep on going” option to build_command. currently supports make and xcodebuild. this is a convenience option; you can specify this behavior directly using build options. iykyk 🌈
  • -o β€” target directory for HTML report files. subdirectories will be created as needed to represent separate invocations of the analyzer. and if you don't specify this option? a directory is created in /tmp (TMPDIR on Mac OS X) to store the reports. it just does that, periodt. ✨
  • -plist β€” output the results as a set of .plist files. (by default the output of scan-build is a set of HTML files, so this is the plot twist πŸ¦‹)
  • -plist-html β€” output the results as a set of HTML and .plist files. both. why choose. πŸ’…
  • --status-bugs β€” set exit status to 1 if it found potential bugs and 0 otherwise. by default the exit status of scan-build is that returned by build_command. important, bestie!! πŸ‘€
  • --use-c++[=*compiler_path*] β€” guess the default compiler for your C++ and Objective-C++ code. use this option to specify an alternate compiler. 🌸
  • --use-cc[=*compiler_path*] β€” guess 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. so -vvv is main character energy, obviously. πŸ”₯
  • -V, --view β€” view analysis results in a web browser when the build completes. cute AND useful. πŸŽ€
  • -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 used by checker-0.160 and earlier. (so like, old-school. retro. vintage.) πŸ’œ
  • -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 cap: more coverage, less speed, that's the tradeoff πŸƒβ™€οΈ
  • -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. numbers!! ⭐
  • -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. those two change the whole ending of the story, so watch out. πŸ‘‘


πŸ‘‘ CHECKERS πŸ‘‘

okay bestie this is the big one, sit down, hydrate πŸ“

The checkers listed below may be enabled/disabled using the -enable-checker and -disable-checker options. a default group of checkers is run unless explicitly disabled. exactly which checkers constitute the default group is a function of the operating system in use; they are listed with --help-checkers. so it's giving "depends on your OS," unfortunately. πŸ’…

  • 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. obviously we do not divide by zero, bestie. ✨
  • 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. it's giving "why did you even write that" energy πŸ’€
  • 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. the classic. πŸ’…
  • 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(). 🚨 (and honestly? deserved.)
  • 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. πŸ’€
  • 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 above example causes analysis reports to be deposited into a subdirectory of /tmp/myhtmldir and to run make with the -j4 option. a different subdirectory is created each time scan-build analyzes a project. the analyzer should support most parallel builds, but not distributed builds. so parallel? slay. distributed? not today bestie. πŸ’…


🫢 AUTHORS 🫢

scan-build was written by Ted Kremenek. documentation contributed by James K. Lowden <jklowden@schemamania.org>. legends, both of them. πŸ‘‘


and that's the whole page, bestie πŸ’– this was clang 15, dated Jun 24, 2022, section 1 of the General Commands Manual. go forth and analyze, you absolute icon πŸ¦‹βœ¨
πŸ“¦ where this page comes from