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

scan-build make does not detect any bugs

I have a very simple .c file, with some obvious bugs inside it. #include struct S { int x; }; void f(struct S s){ } void test() { struct S s; f(s); // warn } int test2(int x){ return 5/(x-x); // warn } int main(){ test(); …
platisd
  • 153
  • 1
  • 9
13
votes
3 answers

Scala tool to remove all unused code

I am writing a Scala plugin for an editor I use that would highlight all unused code paths (could be unused defs, vals, classes and implicits), and give the user an option to yank them out of the .scala file. How can I do this? To simplify the…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
13
votes
6 answers

When to stop following the advice of static code analysis?

I do use static code analysis on a project with more than 100.000 lines of Java code for quite a while now. I started with Findbugs, which gave me around 1500 issues at the beginning. I fixed the most severe over time and started using additional…
Bananeweizen
  • 21,797
  • 8
  • 68
  • 88
13
votes
2 answers

How do I tell Resharper that my IEnumerable method removes nulls?

Given the following code, Resharper will correctly warn me about a possible NullReferenceException on foo.Bar because there could be null elements in the enumerable: IEnumerable foos = GetFoos(); var bars = foos.Select(foo => foo.Bar); One way…
ean5533
  • 8,884
  • 3
  • 40
  • 64
13
votes
9 answers

Any tools to check for duplicate VB.NET code?

I wish to get a quick feeling for how much “copy and paste” coding we have, there are many tools for C# / Java to check for this type of thing. Are there any such tools that work well with VB.NET? (I have seen what looks like lots of repeated code,…
Ian Ringrose
  • 51,220
  • 55
  • 213
  • 317
12
votes
2 answers

Practical differences between control flow graph and call (flow?) graph?

Wikipedia has a definition for a control flow graph. I've also heard terminology thrown around referring to 'call (flow?) graph', but can't find any relevant resources. What is the relationship between the two?
ChaimKut
  • 2,759
  • 3
  • 38
  • 64
12
votes
5 answers

statically analysing Lua code for potential errors

I'm using a closed-source application that loads Lua scripts and allows some customization through modifying these scripts. Unfortunately that application is not very good at generating useful log output (all I get is 'script failed') if something…
Chris
  • 1,825
  • 1
  • 12
  • 12
12
votes
2 answers

Instrumenting C/C++ code using LLVM

I want to write a LLVM pass to instrument every memory access. Here is what I am trying to do. Given any C/C++ program (like the one given below), I am trying to insert calls to some function, before and after every instruction that reads/writes…
Himanshu Shekhar
  • 437
  • 1
  • 5
  • 16
12
votes
1 answer

Should linters config files be in .gitignore?

Files like eslintrc, prettierrc or .editorconfig should be in .gitignore? Exist any good practice related to linters config?
user13101979
12
votes
4 answers

How to run Spotbugs via Maven?

This is my pom.xml:
user1511417
  • 1,880
  • 3
  • 20
  • 41
12
votes
3 answers

How can I lint C++ code to find all unused return values?

I would like to statically inspect all calls to non-void functions where the return value is not used. In effect this would be like applying __attribute__ ((warn_unused_result)) to all non-void functions, but of course for a large project that is…
Nicholas Bishop
  • 1,141
  • 9
  • 21
12
votes
1 answer

How can I find all member field read/writes using Clang?

Given a C++ source code, I want to find the class fields that every function writes and reads. What is the best way of doing this using the Clang frontend? (I'm not asking for a detailed explanation of all the steps; however a starting point for an…
kubuzetto
  • 1,046
  • 1
  • 12
  • 31
12
votes
1 answer

Warnings for uninitialized members disappear on the C++11

I compile this simple program: #include #include using namespace std; struct Foo { int a; int b; }; struct Bar { //Bar() = default; int d; }; int main() { Foo foo; Bar bar; printf("%d %d\n",…
vmario
  • 411
  • 3
  • 15
12
votes
4 answers

Can static analysis detect memory leaks?

Having received my ISTQB certification a long time ago, I remember that it makes the following distinction: -static analysis: performed on the source code, detects unreachable code, unassigned values etc. -dynamic analysis: can detect memory leaks…
John V
  • 4,855
  • 15
  • 39
  • 63
12
votes
1 answer

static code analysis for assembly language

Are there any open-source tools or libraries for static code analysis of simple custom assembly-like languages (for automatically generated programs) and what are they capable of (detecting unused code/registers, giving high-level expressions for…
Thomas
  • 1,001
  • 1
  • 10
  • 20