SCAN-BUILD(1)
β¨ 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#includedfiles. yes, even the headers. we go all the way in π§-enable-checkerchecker_name,-disable-checkerchecker_nameβ enable/disablechecker_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. iftitleisn't specified, a default title is generated for you, no stress π-k,--keep-goingβ add a βkeep on goingβ option tobuild_command. currently supportsmakeandxcodebuild. 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(TMPDIRon Mac OS X) to store the reports. it just does that, periodt. β¨-plistβ output the results as a set of.plistfiles. (by default the output ofscan-buildis a set of HTML files, so this is the plot twist π¦)-plist-htmlβ output the results as a set of HTML and.plistfiles. both. why choose. π--status-bugsβ set exit status to1if it found potential bugs and0otherwise. by default the exit status ofscan-buildis that returned bybuild_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 fromscan-buildand the analyzer. a second and thirdvincreases verbosity. so-vvvis 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 bychecker-0.160and earlier. (so like, old-school. retro. vintage.) π-maxloopNβ specify the number of times a block can be visited before giving up. default is4. 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 forchecker-0.221and 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 ofNSAutoreleasePoolin Objective-C GC mode. πosx.cocoa.NSErrorβ check usage ofNSError**parameters. π«Άosx.cocoa.NilArgβ check for prohibitednilarguments 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 ofCFErrorRef*parameters. βosx.coreFoundation.CFNumberβ check for proper uses ofCFNumberCreate(). βosx.coreFoundation.CFRetainReleaseβ check for null arguments toCFRetain(),CFRelease(), andCFMakeCollectable(). π₯osx.coreFoundation.containers.OutOfBoundsβ checks for index out-of-bounds when using the CFArray API. πosx.coreFoundation.containers.PointerSizedValuesβ warns ifCFArray,CFDictionary, orCFSetare 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 ofgetpw(). π¨security.insecureAPI.getsβ warn on uses ofgets(). π¨ (and honestly? deserved.)security.insecureAPI.mkstempβ warn whenmkstemp()is passed fewer than6X's in the format string. π¨security.insecureAPI.mktempβ warn on uses ofmktemp(). π¨security.insecureAPI.randβ warn on uses ofrand(),random(), and related functions. π¨security.insecureAPI.strcpyβ warn on uses ofstrcpy()andstrcat(). π¨security.insecureAPI.vforkβ warn on uses ofvfork(). π¨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
- debian bookworm: clang-tools-15 1:15.0.6-4+b1 Β· APACHE-2-LLVM-EXCEPTIONS
- ubuntu jammy: clang-tools-15 1:15.0.7-0ubuntu0.22.04.3 Β· APACHE-2-LLVM-EXCEPTIONS
- ubuntu noble: clang-tools-15 1:15.0.7-14build3 Β· APACHE-2-LLVM-EXCEPTIONS
- π the page's license: Apache-2.0 WITH LLVM-exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms