Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "CDT/Archive/designs/StaticAnalysis/CheckerIdeas"

(Checkers)
Line 33: Line 33:
 
:Quick fix
 
:Quick fix
 
   { int x = 5; }
 
   { int x = 5; }
 +
;Buffer over flow
 +
: This code is unsafe
 +
  char x[10];
 +
  char y[15];
 +
  memcpy(x,y,20);
  
 
== Links ==
 
== Links ==
 
* http://www.aristeia.com/ddjpaper1.html
 
* http://www.aristeia.com/ddjpaper1.html

Revision as of 10:51, 27 April 2010

This page is collection of ideas for checker that can be implemented for C/C++ Static Analysis in CDT (Codan). Feel free to add your own ideas or links.

Checkers

Unused #include
 #include <stdio.h>
 int main() { return 1; }
Malloc called without sizeof consideration
 int * arr = (int *)malloc(20); // should be malloc(20*sizeof(int))
Assigned to itself
 x = x;
Result of comparison is constant
 (x==x)
 (!x && x)
Redundant comparison operations
 (!(!x))
 (x!=0 || 0!=x)
Comparison is used on "boolean" values
 0<x<3
 !x>5
Consequent re-assignment without usage (sub-case of Value is never used after assignment)
 x=1;
 x=2;
Value is never used after assignment
 int x;
 x=23;
 return;
Unused local variable
local variable is not used in function
Undeclared variable
This is compiler error - catch early and have a quick fix so Ctrl-1 work like in java, I so like java quick fixes and code generation!
 { x = 5; }
Quick fix
 { int x = 5; }
Buffer over flow
This code is unsafe
 char x[10];
 char y[15];
 memcpy(x,y,20);

Links

Back to the top