Questions tagged [clang-static-analyzer]

Use this tag for the Clang Static Analyzer, an open source source code analysis tool which find bugs in C and Objective-C programs. Use this tag also for Xcode Static Analyzer.

The Clang Static Analyzer is an open source (supported by Apple) source code analysis tool which find bugs in C and Objective-C programs.

It can be run either as a standalone tool or within Xcode. The standalone tool is invoked from the command line, and is intended to be run in tandem with a build of a codebase.

The analyzer is 100% open source and is part of the Clang project. Like the rest of Clang, the analyzer is implemented as a C++ library that can be used by other tools and applications.

296 questions
4
votes
1 answer

Why use __attribute__((__format__ (__printf__,...) in Clang to avoid format string is not a string literal?

It is suggested here and here that to avoid warning 'format string is not a string literal' in Clang, one should use the following __attribute__ code section before the function definition to tell Clang that one of the functions from printf family…
user1343318
  • 2,093
  • 6
  • 32
  • 59
4
votes
2 answers

the right operand of '-' is a garbage value

I am using static analyzer for the first time and having difficulty to figure out the arrows. After looking some similar questions on S.O, I think the problem is the CGSize size is nil value but I am not entirely sure how its working. Here's the…
Obj-Swift
  • 2,802
  • 3
  • 29
  • 50
4
votes
1 answer

Getting HTML output from Xcode's built-in static analysis

When I use the Build & Analyze option in Xcode I see a very useful visual output integrated into the IDE, showing code paths, memory leaks, dead-stores, etc. In Xcode there is a build setting that will allow you to run the static analyser (clang) as…
Jasarien
  • 58,279
  • 31
  • 157
  • 188
4
votes
3 answers

Failing compilation if return value is unused for a certain type

I would like to make compilation fail for some function call but not others. The function call that I want to fail are those that do not handle return values when the value is of a certain type. In the example below, not handling a function…
4
votes
1 answer

Clang static analyzer and continuous integration?

The Clang static analyzer has proved much more reliable than PC-Lint and other Lint variants and similar software in picking up actual issues (not surprisingly, when reading the background). The scan-build method is nice even for automatic builds,…
4
votes
2 answers

Static analysis and the "create rule"

I want to add a category on NSBezierPath to return a CGPathRef for the path. Since this is a core foundation object, I cannot autorelease it, and the caller of the method is responsible for releasing it. By placing either "Copy" or "Create" as part…
3
votes
2 answers

Deep copy of dictionaries gives Analyze error in Xcode 4.2

I have the following method in a NSDictionary category, to do a deep copy, which works fine. I just upgraded from Xcode 4.1 to 4.2, and the Analyze function gives two analyzer warnings for this code, as indicated: - (id)deepCopy; { id dict =…
Dejal
  • 813
  • 6
  • 18
3
votes
2 answers

Potential memory leak if a tuple of a unique pointer is captured in lambda

clang-tidy and scan-build warn about a potential memory leak in this code: #include #include int main() { auto lambda = [tuple = std::make_tuple(std::make_unique(42))] {}; } $ clang-tidy main.cpp -checks="clang*" 1…
Kane
  • 5,595
  • 1
  • 18
  • 27
3
votes
0 answers

Is it possible to ignore xcodebuild analyze warnings from cocoapods and SPM packages?

I use xcodecode analyze to help find static analysis warnings in my code when running CI builds (similar to running the Analyze tool in Xcode directly). It works great finding issues - but the problem is it picks up issues in all code, even that…
Zach
  • 3,909
  • 6
  • 25
  • 50
3
votes
1 answer

Can scan-build or Clang static analyzer discover problems at link time?

While revisiting some codes I've written, I noticed that the build commands in the test scripts did not correctly invoke the scan-build command. The formation of a revision is ready, but I have some question with regard to the capability of…
DannyNiu
  • 1,313
  • 8
  • 27
3
votes
1 answer

Clang Static Analyzer complains about memory leak when using protobuf's set_allocated_*

With the following proto file message Foo { // ... } message MyMessage { Foo foo = 1; } I set foo with the generated set_allocated_foo method which takes ownership of the pointer: MyMessage m; m.set_allocated_foo(new Foo); clang-tidy…
jhasse
  • 2,379
  • 1
  • 30
  • 40
3
votes
0 answers

Excluding header files from clang-tidy analysis

I would like to exclude third party header files from being checked by clang-tidy. From what I can tell, using a negative regular expression for header file exclusion is never going to happen: https://reviews.llvm.org/D34654 Slapping // NOLINT on a…
natersoz
  • 1,674
  • 2
  • 19
  • 29
3
votes
1 answer

Using Clang Static Analyzer directly on bitcode files

I wanted to know if clang analyzer can be made to work directly on bitcode (*.bc) files? Following this post about identification of integer variables that can only have the values 0 or 1, I've started exploring the clang analyzer, and it gave me…
OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87
3
votes
1 answer

How to use AST for both custom front-end action and clang static analysis

I am working on a libTooling based project where I have written a custom frontend action class by referring this. Now I want to run clang static analysis in the same tool. Currently, I am running the tool again for clang static analysis (after…
Hemant
  • 767
  • 6
  • 20
3
votes
1 answer

suppress clang-tidy -Wdocumentation "empty paragraph" errors

I can't seem to find where I might be able to suppress these specific errors or why they are even registering in the first place. error: empty paragraph passed to '@param' command Here is the documentation that I have that is generating this…
Maggie S.
  • 1,076
  • 4
  • 20
  • 30