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
18
votes
7 answers

Dependencies analysis tool - updating regression test cases

Problem Its quite a common problem I would like to think. Adding new code translates into regression - existing test cases become obsolete. Dependencies within the code mean even if you know how to fix this particular regression, there could be…
Pulak Agrawal
  • 2,481
  • 4
  • 25
  • 49
17
votes
2 answers

PHPStan: Property with generic class does not specify its types: TKey, T

I'm running PHPStan on a Symfony project where I have the following relation in a Doctrine entity: /** * @ORM\OneToMany(targetEntity="App\Entity\Course\Slide", mappedBy="chapter", cascade={"persist"}, orphanRemoval=true) *…
AymDev
  • 6,626
  • 4
  • 29
  • 52
17
votes
2 answers

Is it possible to get comments as nodes in the AST using the typescript compiler API?

I would like to extract the comments from a typescript source file, preferably with their line numbers. I tried doing it like this: var program = ts.createProgram(files, { target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS,…
17
votes
3 answers

FindBugs for .NET

In Java is this nice tool called FindBugs. Is there something similar in .Net?
Ludwig Wensauer
  • 1,885
  • 3
  • 32
  • 43
17
votes
7 answers

Languages specifically designed to make static verification easier

A lot of languages (perhaps all of them) are designed to make writing programs easier. They all have different domains, and aim to simplify developing programs in these domains (C makes developing low-level programs easier, Java makes developing…
P Shved
  • 96,026
  • 17
  • 121
  • 165
17
votes
7 answers

Ruby source code analyzer (something like pylint)

Does Ruby have any tools along the lines of pylint for analyzing source code for errors and simple coding standards? It would be nice if it could be integrated with cruisecontrolrb for continuous integration. Or does everyone write such good tests…
Dan Powley
  • 743
  • 4
  • 11
17
votes
6 answers

Do we still need to do static analysis?

My boss thinks that any code we write ( in C/C++) has to comply to the standards specified by a static analysis tool(like MISRA/Lint). My take on this is since compilers are well developed today, is this really required ? Question here is how…
Chaithra
  • 1,130
  • 3
  • 14
  • 22
17
votes
1 answer

Rubocop in html.erb files?

I was curious if there was a way to make Rubocop lint/stylecop html.erb files? I realize that the html would make it hard to style cop the embedded Ruby. Has anyone been able to get Rubocop to do this? If not, is there an equivalent tool for this…
Mike
  • 341
  • 1
  • 4
  • 9
17
votes
3 answers

In C macros, should one prefer do { ... } while(0,0) over do { ... } while(0)?

A customer recently performed static analysis of my employer's C codebase and gave us the results. Among useful patches was the request to change the famous do { ... } while(0) macro to do { ... } while(0,0). I understand what their patch is doing…
Commodore Jaeger
  • 32,280
  • 4
  • 54
  • 44
17
votes
4 answers

Coverity for Java static analysis

I'd like to get comments from people who have used or evaluated Coverity for statically analysing Java-code. I know it's popular in C/C++ world, but is it worth spending the money for Java analysis or am I better off with PMD, Findbugs and other…
auramo
  • 13,167
  • 13
  • 66
  • 88
17
votes
2 answers

How can I run GCC/Clang for static analysis? (warnings only)

Without compiling code, I would like GCC or Clang to report warnings. Is it possible to run the compiler for static analysis only? I can't find a way to pass the compiler warning flags and tell it not to compile. edit: just found that clang has…
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
16
votes
3 answers

code examples for learning LLVM backend programming

I am learning programming LLVM backends. Currently I am interested in analysis passes, later program transformations. (I assume as I will be more fluent with analysis then will be time for program transformations). Could you recommend resources for…
16
votes
1 answer

Why error messages shouldn't end with a punctuation mark in Go?

I have a problem with error text. If I use the error message shown below, the editor's linter gives a warning like this: "error strings should not end with punctuation or a newline": return errors.New("Test!") ^ The question…
muhammed ikinci
  • 667
  • 2
  • 6
  • 18
16
votes
2 answers

Lint-checking tools for Objective-C development

Large projects with multiple developers often result in code that is inconsistent in style. I am looking for a lint-like tool tailored to Objective-C that goes beyond the scope of the Clang Static Analyser and checks for adherence to stylistic…
Aidan Steele
  • 10,999
  • 6
  • 38
  • 59
16
votes
2 answers

Explain System.Diagnostics.CodeAnalysis.SuppressMessage

I have this kind of code in some applications (from microsoft) [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "CounterClockwise", Scope = "member",…
jonathan