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
33
votes
10 answers

Stack Size Estimation

In multi-threaded embedded software (written in C or C++), a thread must be given enough stack space in order to allow it to complete its operations without overflowing. Correct sizing of the stack is critical in some real-time embedded…
jeremytrimble
  • 1,814
  • 1
  • 18
  • 22
32
votes
10 answers

Is there a need for a "use strict" Python compiler?

There exist static analysis tools for Python, but compile time checks tend to be diametrically opposed to the run-time binding philosophy that Python embraces. It's possible to wrap the standard Python interpreter with a static analysis tool to…
cdleary
  • 69,512
  • 53
  • 163
  • 191
32
votes
8 answers

Static analysis of Java call graph

What I'd like to do is scan a set of Java classes, and trace all method calls from a specific method of an Abstract Class, and within that context, build a list of all code which performs some operation (in this case, instantiates an instance of a…
Mark Renouf
  • 30,697
  • 19
  • 94
  • 123
32
votes
1 answer

How to output the AST built using ANTLR?

I'm making a static analyzer for C. I have done the lexer and parser using ANTLR in which generates Java code. Does ANTLR build the AST for us automatically by options {output=AST;}? Or do I have to make the tree myself? If it does, then how to…
Raphael
  • 395
  • 1
  • 5
  • 7
32
votes
1 answer

Tools for generating Haskell function dependency (control flow) graph?

Note not "functional dependency". Are there tools available that allow me to build a static function dependency graph from source code? Something which indicates to me which functions depend on which other ones in a graphical manner.
qrest
  • 3,083
  • 3
  • 25
  • 26
31
votes
13 answers

Measuring the complexity of SQL statements

The complexity of methods in most programming languages can be measured in cyclomatic complexity with static source code analyzers. Is there a similar metric for measuring the complexity of a SQL query? It is simple enough to measure the time it…
epotter
  • 7,631
  • 7
  • 63
  • 88
30
votes
14 answers

Are C++ static code analyis tools worth it?

Our management has recently been talking to some people selling C++ static analysis tools. Of course the sales people say they will find tons of bugs, but I'm skeptical. How do such tools work in the real world? Do they find real bugs? Do they…
David Norman
  • 19,396
  • 12
  • 64
  • 54
30
votes
4 answers

How to build a static code analysis tool?

I m in process of understanding and building a static code analysis tool for a proprietary language from a big company. Reason for doing this , I have to review a rather large code base , and a static code analysis would help a lot and they do not…
codeanalyser
  • 341
  • 1
  • 3
  • 6
30
votes
2 answers

How to keep track of a variable with Clang's static analyzer?

Suppose I'm working with the following C snippet: void inc(int *num) {*num++;} void dec(int *num) {*num--;} void f(int var) { inc(&var); dec(&var); } By using a static analyzer, I want to be able to tell if the value of var didn't change…
ivarec
  • 2,542
  • 2
  • 34
  • 57
29
votes
5 answers

Why won't this seemingly correct .NET code compile?

I'm asking in case I'm missing something obvious, but I think I may have stumbled upon a bug in .NET's compiler. I have two projects in a .NET solution, one visual basic, one C#. C# code, consisting of three overloaded static methods with default…
w.brian
  • 16,296
  • 14
  • 69
  • 118
29
votes
3 answers

Why does the compiler complain that 'not all code paths return a value' when I can clearly see that they do?

I'm trying to figure out why the compiler has a problem with this function. It gives me the "Not all code paths return a value" error, however I cannot see a situation where control-flow would pass to the if( a ) expression without a being true (so…
Dai
  • 141,631
  • 28
  • 261
  • 374
28
votes
5 answers

Is it possible to accelerate clang-tidy using ccache or similar?

Since employing ccache on our CI server, we find that the bottleneck in terms of build time is now our static analysis pass, that uses clang-tidy, among other tools. Does anyone know of a way to accelerate clang-tidy in a similar way to how ccache…
Tim Angus
  • 983
  • 11
  • 26
28
votes
5 answers

Pylint best practices

Pylint looks like a good tool for running analysis of Python code. However, our main objective is to catch any potential bugs and not coding conventions. Enabling all Pylint checks seems to generate a lot of noise. What is the set of Pylint features…
amit
  • 10,612
  • 11
  • 61
  • 60
28
votes
3 answers

How to search for Java API methods by type signature?

Are there any open-source tools available which support searching for Java methods by the set of parameter types and return type? As an example, say I'm looking for a method to generate a hash code for an array of ints. I search for a method which…
mattbh
  • 5,230
  • 2
  • 27
  • 27
28
votes
2 answers

Excluding directory

I am working on a django project and am trying to run pyflakes on an app in it. I need to exclude the "migrations" directory from pyflakes. For pep8 I can do pep8 --exclude=migrations app_name Is there any similar way for pyflakes? I couldn't…
user3148949
  • 578
  • 1
  • 9
  • 22