Questions tagged [code-analysis]

Code Analysis is the process of analyzing the code of the application to discover, review, validate or verify certain properties of the application. This is useful during the process of development and for testing the application before it is put in production mode, especially for checking the security related aspects.

Code Analysis is the process of analyzing the code of the application to discover, review, validate or verify certain properties of the application. This is useful during the process of development and for testing the application before it is put in production mode, especially for checking the security related aspects. Code analysis can be classified from several perspectives, including:

1. What can be analyzed: source code or binary code (byte code) of the application can be analyzed. Both of these categories have their pros and cons.

2. How or When should code be analyzed: Code can be analyzed statically (without executing it) or dynamically (while the application is executed). Static analysis, being conservative, is prone to false positive, but it is exhaustive. On the other hand, dynamic analysis, being very accurate, may miss certain behaviors which are not manifested in any of the execution monitored (because dynamic analysis only analyzes code that is executed - i.e. when certain conditions are met)

3. Purpose of the analysis: Flaws can be found, like NULL pointer dereferencing or passing an ASCII string instead of a Unicode string. Furthermore, aspects of the code can be found, like building various graphs of dependencies or deducing the conditions under which recursion will occur.

1882 questions
36
votes
2 answers

How can I generate a list of function dependencies in MATLAB?

In order to distribute a function I've written that depends on other functions I've written that have their own dependencies and so on without distributing every m-file I have ever written, I need to figure out what the full list of dependencies is…
rmukhopadhyay
  • 613
  • 1
  • 6
  • 9
36
votes
2 answers

Automated docstring and comments spell check

Consider the following sample code: # -*- coding: utf-8 -*- """Test module.""" def test(): """Tets function""" return 10 pylint gives it 10 of 10, flake8 doesn't find any warnings: $ pylint test.py ... Global…
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
36
votes
14 answers

Tool to visualize code flow in Java?

I'm inspired by the C/C++ question for a code flow visualization tool. Is there such a thing for Java servlets or applications?
dacracot
  • 22,002
  • 26
  • 104
  • 152
35
votes
1 answer

PHP_CodeSniffer, PHPMD or PHP Depend

I am looking at doing some static code analysis of an exisiting PHP project, and I'm having trouble understanding the distinctions between PHP_CodeSniffer, PHPMD, and PHP Depend. Are these simply alternatives to the same problem, or do they…
jmans
  • 5,648
  • 4
  • 27
  • 32
35
votes
2 answers

Enabling Microsoft's Code Analysis on .NET Core Projects

Our team uses the Code Analysis feature with a custom ruleset to cause our build to fail if we forget to do things like null checks on method arguments. However, now as we create a new .NET Core project, it doesn't look like Code Analysis is a…
StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315
35
votes
3 answers

Is there a way to measure duplicate code?

I'm looking for a code duplication tool that is language agnostic. It's easy to find language specific code duplication tools (for Java, C, PHP, ...), but I'd like to run some code duplication analysis on a templates in a custom syntax. I don't care…
34
votes
6 answers

Static Actionscript code analysis possibilities

I want to see class, function and variable/property, dependencies visually, like NDepend, but for ActionScript 2 or AS3 code. Any programs or ideas? Use doxygen in some way? FlexUnit?
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
33
votes
5 answers

How to fix Visual Studio 2022 Warning CA1416 "Call site reachable by all platforms" but "only supported on: 'windows'"?

So I have a C# class library project that I only intend to use on Windows. It contains some classes that use the System.Drawing.Image class which is only available on Windows. After upgrading to Visual Studio 2022 and setting the target framework…
RonC
  • 31,330
  • 19
  • 94
  • 139
32
votes
8 answers

C# Call Graph Generation Tool

I just got a heaping pile of (mostly undocumented) C# code and I'd like to visualize it's structure before I dive in and start refactoring. I've done this in the past (in other languages) with tools that generate call graphs. Can you recommend a…
Waylon Flinn
  • 19,969
  • 15
  • 70
  • 72
32
votes
3 answers

What is a "naive" algorithm, and what is a "closed - form" solution?

I have a few questions regarding the semantics of terminology used when describing algorithms. Firstly, what is meant by a 'naive' algorithm? How does this differ from other solutions to a given problem? What other forms can solutions…
user559142
  • 12,279
  • 49
  • 116
  • 179
32
votes
2 answers

CA1001 implement IDisposable on async method

Consider following code: public class Test { public async Task Do() { await Task.Delay(200); using (var disposable = new Disposable()) { disposable.Do(); } } } public class Disposable :…
Jan Muncinsky
  • 4,282
  • 4
  • 22
  • 40
32
votes
0 answers

Writing Coverity model: pointer in struct ALWAYS points to tainted data

I reguarly check lwIP, a free TCP/IP stack with Coverity. As a network stack, we have untrusted data coming in from the network which is stored in struct pbuf (some members omitted for clarity): struct pbuf { void *payload; u16_t len; u16_t…
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

What tools do you use for static code analysis?

This question on Cyclomatic Complexity made me think more about static code analysis. Analyzing code complexity and consistency is occasionally useful, and I'd like to start doing it more. What tools do you recommend (per language) for such…
Chris
  • 6,761
  • 6
  • 52
  • 67
30
votes
2 answers

Finding all references to a method with Roslyn

I'm looking to scan a group of .cs files to see which ones call the Value property of a Nullable (finding all references). For example, this would match: class Program { static void Main() { int? nullable = 123; int value…
James Ko
  • 32,215
  • 30
  • 128
  • 239