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
11
votes
1 answer

clang scan-build reports with compiler warnings?

clang's scan-build driver for the static analyzer generates pretty html reports. But these only contain the issues the analyzer finds. Is there way to generate the same kind of reports for warnings (and errors) from the compiler itself?
dantje
  • 1,739
  • 1
  • 13
  • 25
10
votes
5 answers

How can I fix this clang warning: "Object with +0 retain counts returned to caller where +1 (owning) retain count is expected"?

I have a piece of Objective-C code that looks like the following: - (NSString *)copyData:(NSData *)data { NSString *path = [[[self outputDirectory] stringByAppendingPathComponent:@"archive"] stringByAppendingPathExtension:@"zip"]; …
mipadi
  • 398,885
  • 90
  • 523
  • 479
10
votes
2 answers

Is the clang static analyzer confused by popping the front from a list of unique_ptrs?

The following C++11 code is a minimal example of what I believe triggers a false positive in clang: #include #include #include class ElementType {}; int main(int argc, const char * argv[]) { …
Thierry
  • 1,099
  • 9
  • 19
10
votes
2 answers

Why would the outcome of this shift left operation be deemed undefined?

I am working with a mix of C90 and C99 (cannot fully use C99 for reasons I better don't discuss, because they aren't good for my blood pressure and would endanger the life of the person preventing us from moving our code base into the current…
0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
9
votes
1 answer

Trying to suppress clang false positive leak warning

I am using clang static analysis under Xcode 6.4 (6E35b), and getting a false positive warning about a potential memory leak. I do explicitly free the memory in question, but the freeing happens in a different compilation unit. Here is my…
9
votes
1 answer

How to find memory leaks with Clang

I have installed Clang in my machine (ubuntu) in order to find memory leaks in my C code. I wrote a sample code in order to check the working of it which is as follows: /* File: hello.c for leak detection */ #include #include…
9
votes
1 answer

How to get function name using FunctionDecl *D in clang

In one of my checker, i am using FunctionDecl class to get the function declaration. Now i want to get the name of the function for which i enter into the checkASTDecl method. As we know that in checkASTDecl() we get pointer of class FunctionDecl.…
user1497818
  • 375
  • 1
  • 7
  • 16
8
votes
2 answers

clang-analyze: how to avoid "garbage value" warning?

When checking #include #include int main(void) { char c[20]; size_t l; l = fread(c, sizeof c, 1, stdin); if (l != 1) return 1; return c[0] == 42; } with clang, I get $ clang --analyze -Xclang…
ensc
  • 6,704
  • 14
  • 22
8
votes
3 answers

Clang Static Analyzer doesn't find the most basic problems

I wanted to try out the clang static analyzer. I'm on Windows and built clang with Visual Studio. It seems to work, but at the same time it seems to be extremely useless. I made an example file example.c int main(void) { int h = 0; return…
CodeMonkey
  • 4,067
  • 1
  • 31
  • 43
8
votes
0 answers

Possible false-positive - clang static analyzer and regex

A colleague sees a strange warning by clang static analyzer (actually from clang-check). This code: #include int main() { std::regex_match("jee", std::regex("lol")); return 0; } produces analyzer…
lstipakov
  • 3,138
  • 5
  • 31
  • 46
8
votes
2 answers

How can I enable clang-tidy's "modernize" checks?

I just installed ClangOnWin,and I'm trying to get clang-tidy's "modernize" checks to work. Unfortunately, clang-tidy doesn't seem to know about them: clang-tidy -list-checks foo.cpp -- | grep modernize produces no output. The "modernize" checks are…
KnowItAllWannabe
  • 12,972
  • 8
  • 50
  • 91
7
votes
1 answer

Strange Xcode Analyze results

When I Analyze my project in Xcode, I get a few strange errors. All of this code is part of a single method which creates arrays that can be used to make MKAnnotations. Sorry if this is an inundation of code—I did my best to comment out the…
eric.mitchell
  • 8,817
  • 12
  • 54
  • 92
7
votes
1 answer

Xcode static analyzer and copyWithZone

The Xcode 4 static analyzer flags this method as a having an over-released return value when that does not seem to be the case. - (id)copyWithZone:(NSZone *)zone { return [[[self class] allocWithZone:zone] initWithURL:self.url…
titaniumdecoy
  • 18,900
  • 17
  • 96
  • 133
7
votes
1 answer

How can I match a pointer to a null object?

I'd like to match on all the ways a particular argument to a function can be null. Right now I'm using hasArgument( 3, anyOf( cxxNullPtrLiteralExpr() ,integerLiteral() // Technically this would alert on a…
Tom Ritter
  • 99,986
  • 30
  • 138
  • 174
7
votes
1 answer

Clang user documentation

I was unsure whether to ask here or in superuser, but this site seemed more appropriate I'm looking for documentation/analysis on Clang specifically for these two areas: comparison of warnings provided by Clang vs. GCC I'm specifically looking…
Šimon Tóth
  • 35,456
  • 20
  • 106
  • 151
1
2
3
19 20