Questions tagged [static-analysis]

"Static Analysis" refers to the software tools (or their use) to analyze application code for arbitrary properties, such as errors (uninitialized variables, possible SQL injection-attack, is this code-dead, can an argument be null,...) or structure (what is the call graph for this code? is there duplicate code? what information is passed between components?).

Static analysis refers to the software tools (or their use) to analyze application code for arbitrary properties, such as errors (uninitialized variables, possible SQL injection-attack, is this code-dead, is there duplicate code, can an argument be null), or structure (what is the call graph for this code? what information is passed between components?).

The variety of questions that one might ask about application properties is endless. Usually, one needs a tool customized to answer each individual question, for each individual language. And each such tool typically requires a lot of engineering, as most of them have to contain a significant part of a compiler front end just to read the source code and understand the meaning of the source code entities. Consequently, such tools are rare for the specific question you want to ask; where they exist, there are as many static analysis software tools are there are questions, although often a set of questions are rolled up into a single tool.

(In contrast, dynamic analysis refers to collecting data about interesting properties as an application program actually executes, e.g., "did this sum overflow at runtime?". In principle, a static analysis tool can provide exactly the information that dynamic analysis can, just by simulating the execution of the program, but its a lot of work to build such a simulator when there's already a computer lying around that is willing to do it for no extra effort.)

2152 questions
15
votes
2 answers

Dependencies graph for large PHP application

I've recently inherited a large PHP application with NO objects/modules/namespaces...only a lot of files containing functions. Of course, there is a LOT of dependencies (and all files and almost always included). I'm looking for a tool that could…
Loïc Février
  • 7,540
  • 8
  • 39
  • 51
15
votes
2 answers

Static analysis of noexcept "violations" in C++

I'm trying to write exception safe code. I find that using C++11's noexcept specifier makes this goal a whole lot more achievable. The general idea, of course, is that a function should be marked as 'noexcept' if, and only if all the functions that…
Kristian Spangsege
  • 2,903
  • 1
  • 20
  • 43
15
votes
4 answers

IDisposable created within a method and returned

I happy coded quite a project that works fine and do not manifest any oddities at runtime. So I've decided to run static code analysis tool (I'm using Visual Studio 2010). It came out that rule CA2000 is being violated, message as follows: Warning -…
Krzysztof Jabłoński
  • 1,890
  • 1
  • 20
  • 29
14
votes
3 answers

How to statically analyze reference types passed to each bytecode instruction?

I have rewritten the question (the question remains the same, just with less background noise) in hopes of creating less confusion directed at all the wrong things - due to this, some of the comments below may seem out of context. Analyzing Java…
Sami Koivu
  • 3,640
  • 3
  • 24
  • 23
14
votes
2 answers

Exclude all generated code from dartanalyzer

I am trying to exclude all generated files from a package using the following analysis_options.yaml file. include: package:pedantic/analysis_options.yaml analyzer: strong-mode: implicit-casts: false implicit-dynamic: false …
wigy
  • 2,174
  • 19
  • 32
14
votes
0 answers

How-to use Clang Static Analyzer on Windows?

I'm currently trying to integrate the Clang Static Analyzer v9.0.1 into my CMake v3.16.5 build system using the Microsoft Visual C++ Compiler (MSVC) v19.25.28610.4 on a Windows v10.0.18363.720 operating system. Everything is build for the…
14
votes
3 answers

How to find out if (the source code of) a function contains a loop?

Let's say, I have a bunch of functions a, b, c, d and e and I want to find out if they directly use a loop: def a(): for i in range(3): print(i**2) def b(): i = 0 while i < 3: print(i**2) i += 1 def c(): …
finefoot
  • 9,914
  • 7
  • 59
  • 102
14
votes
5 answers

Retrieving the type of auto in C++11 without executing the program

I have some C++11 code using the auto inferred type that I have to convert to C++98. How would I go about converting the code, substituting in the actual type for all instances of auto?
user1825464
  • 271
  • 3
  • 6
14
votes
5 answers

Tools for finding Shared Mutable data bugs in Java

I have a large legacy system to maintain. The codebase uses threads all over the place and those threads share a lot of mutable data. I know, sounds bad. Anyway, don't answer "rewrite the whole application from scratch" or I'll vote you down :-) I…
auramo
  • 13,167
  • 13
  • 66
  • 88
14
votes
1 answer

How to get Vera++ to ignore sections of code for some/all rules?

I am using Vera++ to perform some static analysis on my C++ code. (in Visual Studio 2008) However, I have some blocks of code that I know, and accept, will break certain rules. I'd like to be able to somehow tell Vera++ to avoid these methods or…
Dave
  • 1,696
  • 4
  • 23
  • 47
14
votes
6 answers

How can I find copy/paste (duplicate, clone) code in Perl?

I've searched the Internet for a while now and I have not been able to find any free (or cheap) tools/utilities/modules that can analyze a set of Perl files (modules or scripts) and flag duplicate or cloned or copy/pasted code. I'm better now, but I…
Kurt W. Leucht
  • 4,725
  • 8
  • 33
  • 45
14
votes
1 answer

How do I exclude library headers from my Visual Studio static code analysis?

I have setup buildbot to compile my Qt/C++ application with the /analyze flag. However the analysis is also delving into the qt headers which I don't care about: c:\qt\qt-everywhere-opensource-src-4.8.1\src\corelib\tools\qvector.h(547) : warning…
Phil Hannent
  • 12,047
  • 17
  • 71
  • 118
13
votes
3 answers

Can anything warn me against type.equals(incompatibleType)?

Is there any tool that can warn me against the following sort of code: if ( someClass.equals( someString )) For example: if ( myObject.getClass().equals( myClassName )) Such a thing is legal Java (equals takes an Object) but will never evaluate to…
Richard Kennard
  • 1,325
  • 11
  • 20
13
votes
1 answer

Should annotations in jar305.jar be preferred over similar annotations in annotation.jar for FindBugs?

In the FindBugs distribution, annotations.jar is not a subset of jsr305.jar. However, several annotations seem to be duplicated (either exactly, or very closely). Should I prefer an annotation in jsr305.jar if I have a choice? Note that I'm not just…
Greg Mattes
  • 33,090
  • 15
  • 73
  • 105
13
votes
3 answers

Ignore certain files when using clang-tidy

I'm trying to integrate clang-tidy with cmake, but there are some files that belong to a particular target which I would like to ignore. Is there any way to make clang-tidy to ignore files under certain directory or whose name matches a certain…
Dan
  • 2,452
  • 20
  • 45