Difference between revisions of "List of Code Linters"

From RidgeRun Developer Connection
Jump to: navigation, search
Line 73: Line 73:
 
! Linter !! ptr2int !! ptr2long !! int2ptr !! long2ptr !! ptr2int return !! ptr2long return !! int2ptr return !! long2ptr return
 
! Linter !! ptr2int !! ptr2long !! int2ptr !! long2ptr !! ptr2int return !! ptr2long return !! int2ptr return !! long2ptr return
 
|-
 
|-
| g++ -Weverything || Y || Y || N || N || Y || Y || Y || Y
+
| g++ -Weverything || Y<ref name=no-compile>Wont even compile, still considered as a catch though</ref> || Y || N || N || Y || Y || Y || Y
 
|-
 
|-
 
| clang++ -Weverything || Y || Y || N || N || Y || Y || Y || Y
 
| clang++ -Weverything || Y || Y || N || N || Y || Y || Y || Y
 
|-
 
|-
| cppcheck || Y || Y || N || N || Y || Y || Y || Y
+
| cppcheck<ref name=enable-all>Ran with --enable=all</ref> || Y || Y || N || N || Y || Y || Y || Y
 +
|-
 +
| cpplint || N || N || N || N
 
|-
 
|-
 
| clang-tidy ||  Y || Y || N || N || Y || Y || Y || Y
 
| clang-tidy ||  Y || Y || N || N || Y || Y || Y || Y
Line 83: Line 85:
 
| clang-analyze ||  Y || Y || N || N || Y || Y || Y || Y
 
| clang-analyze ||  Y || Y || N || N || Y || Y || Y || Y
 
|}
 
|}
 +
<references/>
  
 
==== Memory Leaks (function variables) ====
 
==== Memory Leaks (function variables) ====

Revision as of 22:43, 15 April 2020

C++

Tools Considered

g++
The plain compiler invoked as g++ -Weverything -c on the file. Not ideal nor a real linter, but mainly for convenience.
clang++
The plain compiler invoked as clang++ -Weverything -c on the file. Not ideal nor a real linter, but mainly for convenience.
cppcheck
A C/C++ linter with a novel flow sensitive analysis.
cpplint
A linter built by google specifically for their coding standard.
clang-tidy
A clang-based C++ linter
clang-analyzer
Another clang-based static c++ linter with awesome reporting features.

Checks

64 Bit Compatibility

// return cast from ptr to int
int ptr_to_int()
{
  void * p = 0;
  return p;
}

// return cast from ptr to long
long ptr_to_long()
{
  void * p = 0;
  return p;
}

// return cast from int to ptr
void * int_to_ptr()
{
  int i = 0;
  return i;
}

// return cast from long to ptr
void * long_to_ptr()
{
  long l = 0;
  return l;
}

int main ()
{
  void * p = 0;

  // assign address to int
  int i = p;

  // assign address to long
  long l = p;

  //assign int to address
  p = i;

  //assign long to address
  p = l;

  return 0;
}
Linter ptr2int ptr2long int2ptr long2ptr ptr2int return ptr2long return int2ptr return long2ptr return
g++ -Weverything Y[1] Y N N Y Y Y Y
clang++ -Weverything Y Y N N Y Y Y Y
cppcheck[2] Y Y N N Y Y Y Y
cpplint N N N N
clang-tidy Y Y N N Y Y Y Y
clang-analyze Y Y N N Y Y Y Y
  1. Wont even compile, still considered as a catch though
  2. Ran with --enable=all

Memory Leaks (function variables)

#include <glib.h>
#include <stdlib.h>

int main ()
{
  // New
  int *a = new int;

  // Malloc
  int *b = (int *)malloc(sizeof (int));

  // Calloc
  int *c = (int *)calloc(1, sizeof (int));

  // Realloc
  int *d = (int *)realloc(0, sizeof (int));

  // External library
  int *e = (int *)g_malloc(sizeof (int));

  return 0;
}
Linter New Malloc Calloc Realloc
g++ -Weverything N N N N
clang++ -Weverything N N N N
cppcheck Y Y Y Y
cpplint N N N N
clang-tidy Y Y Y Y
clang-analyze Y Y Y Y