Options:
C++20
C++17
C++14
C++11
C11
C99
C89
Visual Studio 2013
Visual Studio 2015
Visual Studio 2019 (x64)
No Standard Library
No Coding Standard
AUTOSAR 19
MISRA C 2012
MISRA C 2004
MISRA C++ 2008
Run
Clear
For Evaluation Purposes Only
/* Welcome to the PC-lint Plus interactive demo. Press the 'Run' button above to analyze the sample code in this text area using PC-lint Plus. Messages will be displayed under the corresponding line. The 'Clear' button will hide these messages. You can enter your own sample code to evaluate PC-lint Plus. The options above can be used to choose whether to use C or C++ and to enable optional features such as MISRA rule enforcement. Note that MISRA support should be used with the matching language. E.g. if using MISRA C 2012 the language (which defaults to C++17) should be changed to C99 or C11. */ #include
#include
/* Library Function Semantics */ /* Floating Point Value Tracking */ void r(double); void cr() { r(42); } void r(double x) { printf("%d", acos(x)); } /* Queries and Metrics - custom messages (see configuration pane) */ typedef int INT; typedef int INT_t; void foo(INT x, INT_t y) { if (x == 1) { /* ... */ } if (1 == x) { /* ... */ } if (x == y) { /* ... */ } } /* User-defined metrics (see configuration pane) */ struct X { }; struct Y : private X { }; struct Z : private Y { }; struct W : private Z { }; /* Value Tracking */ int f(void); int g() { return f(); } int f() { static int x = g(); return x++; } /* Precision Bit Tracking */ void z(char c1, char c2) { if ( (c1 & 13) + (c2 & 8) == 6 ) { } } /* Value Tracking */ int w(int a) { int* p = new int; return 5 / a; } int q(int b, int c) { return w(0) + c + sizeof(W); }
/* This pane is a PC-lint Plus configuration file (extension ".lnt") where options can be provided before analyzing the code in the source file pane. */ /* Queries - New feature in 2.0, see chapter 15 of the Reference Manual for details */ /* Emit a custom message when a typedef is declared without a '_t' prefix. */ -astquery(TypedefDecl : { $name = getNameAsString() not $name.endsWith("_t") message(8001 "typedef name " $name " does not end with _t suffix") }) /* Emit a custom message when an identifier appears as the LHS of the '==' but not the RHS, e.g. 'if (var == 1)' instead of 'if (1 == var)'. */ -astquery(BinaryOperator() : { getOpcodeStr() == "==" $lhs_decl_ref = getLHS().ignoreParenCasts().DeclRefExpr() $rhs_decl_ref = getRHS().ignoreParenCasts().DeclRefExpr() $lhs_decl_ref && !$rhs_decl_ref message(8002 "variable " $lhs_decl_ref.getDecl() " could appear on RHS of == operator") }) /* Metrics - new feature in 2.0, see chapter 10 of the Reference Manual for details */ /* Messages produced by the following options will appear with message number 888. */ /* Emit a message when the cylcomatic complexity of a function exceeds N. */ +metric(function.cyclomatic_complexity > 1) /* Emit a message when the depth of ancestors in a class inheritance hierarchy exceeds 2 */ +metric(class.inheritance_levels_to_base = count(class.immediate_bases) == 0 ? 0 : 1 + max(class.immediate_bases, class.inheritance_levels_to_base) ) +metric(class.inheritance_levels_to_base > 2)