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
16
votes
2 answers

Tool to automatically rewrite a bash script with proper quoting?

I'm contemplating to make all bash scripts of a large codebase shellcheck compliant, but the task is overwhelming, because too many developers have historically ignored rule number one of all shell scripting: always use quotes. It would be helpful…
user2394284
  • 5,520
  • 4
  • 32
  • 38
16
votes
2 answers

How does ReSharper know this return type is never null?

I'm using ReSharper 5.0, and am wondering how its code analysis function knows to higlight the following assemblies == null with the comment "Expression is always false". var directory = new DirectoryInfo("somedir"); FileInfo[] assemblies =…
Rob Levine
  • 40,328
  • 13
  • 85
  • 111
16
votes
4 answers

CA2213 code analysis rule and auto-implemented properties

I use static code analysis in our projects to check for code violations. One of extensively used rules is CA2213, which checks for correct disposing of disposable fields. I noticed CA2213 does not check disposing of auto implemented properties.…
Zvonko
  • 363
  • 2
  • 19
16
votes
5 answers

Static source code analysis with LLVM

I recently discover the LLVM (low level virtual machine) project, and from what I have heard It can be used to performed static analysis on a source code. I would like to know if it is possible to extract the different function call through function…
Phong
  • 6,600
  • 4
  • 32
  • 61
16
votes
4 answers

What program slicing tools actually exist?

I've just been introduced to the term "program slicing." It makes perfect sense that one would want such functionality, but does it exist anywhere? The term is 20 years old now, and I see there are lots of publications, research papers, etc. But…
feuGene
  • 3,931
  • 2
  • 33
  • 46
16
votes
3 answers

What is the difference between Data Flow Analysis and Abstract Interpretation

What is the difference between Data Flow Analysis and Abstract Interpretation and are they used for the same purpose? What are the pros and cons of these two relative to each other.
15
votes
1 answer

How to use LLVM to generate a call graph?

I'm looking into generating a call-graph for the linux kernel that would include function pointers (see my previous question Static call graph generation for the Linux kernel for more information). I've been told LLVM should be suitable for this…
addalbx
  • 545
  • 1
  • 4
  • 9
15
votes
6 answers

Code analysis tools for Android

Is there any static code analysis tools for Android that would pick up simple things like NullPointerExceptions from trying to access an object that might be null (without checking for it first)... Tools like resharper on C# projects do this quite…
Mike Hudgell
  • 307
  • 1
  • 3
  • 13
15
votes
7 answers

Is there a way to enforce using tabs instead of spaces in Java?

CheckStyle offers to check for consistent use of spaces, but sadly lacks the opposite idea: Force source code to use tabs. Is there some way to add this functionality? It does not have to be CheckStyle, other tools are welcome as well. Same as this…
Craig P. Motlin
  • 26,452
  • 17
  • 99
  • 126
15
votes
2 answers

Contract that ensures the IEnumerable is not empty

The given code static public int Q() { return Enumerable.Range(0, 100) .Select(i => i) .First(); } emits the following warning: warning : CodeContracts: requires unproven: Any(source) If I remove .Select() clause it…
zerkms
  • 249,484
  • 69
  • 436
  • 539
15
votes
2 answers

How to immediately see Swift errors in AppCode?

Is there a way to immediately see Swift errors in AppCode? On their website they talk about static code analysis, but nowhere could I find a claim that this happens instantly. When you type some Swift code in Xcode you usually see warnings, errors…
15
votes
3 answers

How to exclude files from Eclipse indexing (Static Code Analysis)?

I have a makefile project comprised of many source, header and other files, which I am trying to convert to an Eclipse "native" project. The problem that the Indexer reports errors and warning on files that exist in the directories but are excluded…
ysap
  • 7,723
  • 7
  • 59
  • 122
15
votes
13 answers

How do I enforce null checking?

I'm working on a large project where, even with 10s of 1000s of automated tests and 100% code coverage, we're getting a ridiculous number of errors. About 95% of errors we get are NullReferenceExceptions. Is there any way to enforce null-checking at…
Juliet
  • 80,494
  • 45
  • 196
  • 228
15
votes
2 answers

Applicative functors analysis

I've been trying to learn about static analysis of applicative functors. Many sources say that an advantage of using them over monads is the susceptibility to static analysis. However, the only example I can find of actually performing static…
aurickQ
  • 153
  • 6
15
votes
2 answers

How to test binary compatibility automatically?

Can it be done before compiling, by comparing code? Is there any tools already doing this?