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
67
votes
5 answers

What's the current state of static analysis tools for Scala?

I saw a StackOverflow question regarding static analysis in Scala, but that one was answered in 2009. As you know, the Scala tools are changing very rapidly. I was therefore wondering if someone familiar with the current state of static analysis…
marekinfo
  • 1,434
  • 1
  • 12
  • 12
62
votes
1 answer

Should I use the final modifier when declaring case classes?

According to scala-wartremover static analysis tool I have to put "final" in front of every case classes I create: error message says "case classes must be final". According to scapegoat (another static analysis tool for Scala) instead I shouldn't…
sscarduzio
  • 5,938
  • 5
  • 42
  • 54
61
votes
2 answers

Implicit memory aliasing in for loop

I'm using golangci-lint and I'm getting an error on the following code: versions []ObjectDescription ... (populate versions) ... for i, v := range versions { res := createWorkerFor(&v) ... } the error is: G601: Implicit memory aliasing in…
Dean
  • 6,610
  • 6
  • 40
  • 90
59
votes
8 answers

How to raise warning if return value is disregarded?

I'd like to see all the places in my code (C++) which disregard return value of a function. How can I do it - with gcc or static code analysis tool? Bad code example: int f(int z) { return z + (z*2) + z/3 + z*z + 23; } int main() { int i =…
Drakosha
  • 11,925
  • 4
  • 39
  • 52
59
votes
3 answers

javax.annotation: @Nullable vs @CheckForNull

What is the difference between the two? Both seem to mean that the value may be null and should be dealt with accordingly i.e. checked for null. Update: The two annotations above are part of…
vitaly
  • 2,755
  • 4
  • 23
  • 35
57
votes
9 answers

Static Analysis tool recommendation for Java?

Being vaguely familiar with the Java world I was googling for a static analysis tool that would also was intelligent enough to fix the issues it finds. I ran at CodePro tool but, again, I'm new to the Java community and don't know the vendors. What…
sergeb
  • 2,484
  • 3
  • 22
  • 20
54
votes
7 answers

How to determine maximum stack usage in embedded system with gcc?

I'm writing the startup code for an embedded system -- the code that loads the initial stack pointer before jumping to the main() function -- and I need to tell it how many bytes of stack my application will use (or some larger, conservative…
David Cary
  • 5,250
  • 6
  • 53
  • 66
54
votes
7 answers

Dead code identification (C++)

I have a large legacy C++ project compiled under Visual Studio 2008. I know there is a reasonably amount of 'dead' code that is not accessed anywhere -- methods that are not called, whole classes that are not used. I'm looking for a tool that will…
Rob Walker
  • 46,588
  • 15
  • 99
  • 136
48
votes
3 answers

Is there a static analysis tool like Lint or Perl::Critic for shell scripts?

Are there any shell (specifically bash or ksh) checkers that test shell scripts for style, best practices, naming conventions, etc? (Something like Lint for C, or Perl::Critic for Perl.) I know with ksh you can do syntax checking by running ksh -n…
BrianH
  • 7,932
  • 10
  • 50
  • 71
47
votes
2 answers

@GuardedBy annotation with java.util.concurrent.locks.ReadWriteLock

What is a proper/preferred way to annotate fields that are protected with a ReadWriteLock so that tools like FindBugs can leverage the annotation? Should the name of the ReadWriteLock simply be written in the @GuardedBy annotation. Is there ever a…
Greg Mattes
  • 33,090
  • 15
  • 73
  • 105
47
votes
34 answers

Why do code quality discussions evoke strong reactions?

I like my code being in order, i.e. properly formatted, readable, designed, tested, checked for bugs, etc. In fact I am fanatic about it. (Maybe even more than fanatic...) But in my experience actions helping code quality are hardly implemented. (By…
46
votes
9 answers

Are there any tools for performing static analysis of Scala code?

Are there any tools for performing static analysis of Scala code, similar to FindBugs and PMD for Java or Splint for C/C++? I know that FindBugs works on the bytecode produced by compiling Java, so I'm curious as to how it would work on…
Roman Kagan
  • 10,440
  • 26
  • 86
  • 126
43
votes
4 answers

Disable Sonar duplications on Entity, DTO packages

Is there any way to disable certain metrics from selected packages in Sonar? I use Sonar to analyze my project and in Entity and DTO packages I have some code that is equal - the same field ID with annotations, etc is being reported as a duplication…
Arek
  • 1,941
  • 4
  • 22
  • 27
41
votes
6 answers

C#/.NET analysis tool to find race conditions/deadlocks

Is there a tool that analyses .NET code and finds race conditions? I have a bit of code that has a public static property that gets or creates a private static field. It also has a public static method that sets this field to null (...yes, I…
Steve Dunn
  • 21,044
  • 11
  • 62
  • 87
41
votes
3 answers

Tentative definitions in C and linking

Consider the C program composed of two files, f1.c: int x; f2.c: int x=2; My reading of paragraph 6.9.2 of the C99 standard is that this program should be rejected. In my interpretation of 6.9.2, variable x is tentatively defined in f1.c, but this…
Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281