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
1
vote
1 answer

Plaintext password protection

I am designing a C application using a third-party implementation of the PKCS#11 cryptography API monitoring cryptographic operations of a Hardware Security Module. The PKCS#11 standard specifies (among other things) basic access control on…
1
vote
1 answer

Learning how to prove Frama-C pre-condition goals

I have the following sample code: typedef struct { BYTE fs_type; /* FAT sub-type (0:Not mounted) */ BYTE drv; /* Physical drive number */ } FATFS_temp; FATFS_temp *FatFs_temp[1]; /* Pointer to the file system…
adrianX
  • 619
  • 7
  • 21
1
vote
3 answers

How do I check C source file for missing return error checking?

Suppose you have a code like this: int* a = (int*) malloc(20); a[3]=2; pid_t q = fork(); if(!q) { char *a[5]; for (q=4; ;--q) { if(q<0) break; a[q]="q"; } execve("q", a, NULL); } if(q) kill(q, 9); free(a); It builds…
Vi.
  • 37,014
  • 18
  • 93
  • 148
1
vote
2 answers

What statistical distribution is used to benchmark an algorithm?

I have benchmarked my algorithm, it run for 1000 times. Now I have all time values and at this point it would be interesting to know the mean, standard deviation, median. The problem is that I don't know what is correct statistics to use to estimate…
Nico Mkhatvari
  • 103
  • 2
  • 11
1
vote
2 answers

How to create a list containing the LOC for each function (C++)

I want to make sure that the function body for each function fits on the screen. Therefore I want to to generate a list that contains the LOC for each function (in a .cpp/.h - file, or better in all source code files in a directory). For example the…
levzettelin
  • 2,600
  • 19
  • 32
1
vote
1 answer

How to extract Linux kernel data objects statically?

I am trying to figure out the easiest way to extract kernel data objects using static analysis tools, I found CIL as one option but looks like its more embedded in to GCC and may not be feasible when we need to run it with cross compiler. I wonder…
1
vote
0 answers

Usage before assignment detection in a Javascript code

I'm taking on a task to find issues in a large number of short Javascript codes. One of the things I'm looking for is instance of a variable usage before explicit assignment, like so: var a; var b = a + 10; // a is not explicitly assigned a…
Mansour
  • 1,787
  • 2
  • 20
  • 33
1
vote
0 answers

Could PureAttribute only be guaranteed when manipulating primitive types?

JetBrains annotations: Indicates that a method does not make any observable state changes. The same as System.Diagnostics.Contracts.PureAttribute Microsoft Code Contracts: Indicates that a type or method is pure, that is, it does not make any…
Den
  • 1,827
  • 3
  • 25
  • 46
1
vote
0 answers

Find redundant function calls within call tree?

I have a function which I believe is called multiple times in the same code path - like c() in the example given here. Is there any way to statically find what code paths call c(), and to see if any of those paths lead to redundant calls? Thanks!
user693861
  • 339
  • 3
  • 15
1
vote
1 answer

LLVM fails to detect very simple loop trip count

I'm trying to understand how the loop trip count calculation happens in LLVM using the Scalar Evolution analysis. However, I can't get a simple test case to work. I have the following test program: // bug.cpp int main() { for (int i = 0; i < 16;…
tdenniston
  • 3,389
  • 2
  • 21
  • 29
1
vote
0 answers

Tool or compilerflag to report missing cases in a switch statement

Is there a tool or a compiler flag to help identify switch statements missing one or more case statements? The idea is enum Colors { Black, Blue } and Colors c = Colors.Black; then a number of places in the code I have switch(c) { case Black: …
Carlo V. Dango
  • 13,322
  • 16
  • 71
  • 114
1
vote
0 answers

Static analysis tool for Javascript geared towards error checking?

I know of JSLint/JSHint, but are there JavaScript static analysis tools geared towards error checking rather the syntactical error? For example: new Date(2001, 12, 31) This is generally an error, since month in Date constructor is designed to take…
voidvector
  • 1,976
  • 2
  • 18
  • 19
1
vote
1 answer

Elixir: conflict between pattern matching and type specification.

if I have multiple clauses of a function, with their type spec: i) @spec foo(number)::string ii) @spec foo(string):: number iii) @spec foo(tuple):: string When I call foo with a tuple (in a unit test), would it first try to pattern match with…
tldr
  • 11,924
  • 15
  • 75
  • 120
1
vote
0 answers

Automatically specialize C header files to the current platform and configuration: how?

I want to be able to write small scripts to analyze the macros, prototypes, etc., that are effectively included on the platform I am compiling on when I #include the official C header files associated with large external libraries in my C programs.…
Carl Sturtivant
  • 137
  • 1
  • 3
1
vote
2 answers

How to estimate a variable's value with static analysis?

I want to write a program to do this, based on Soot's build-in Reaching-Definition analysis. Now I'm wondering is this the correct approach? I searched and found nobody seems to ever be interested in this direction. Any suggestions?
Elderry
  • 1,902
  • 5
  • 31
  • 45