cppcheck java_Cppcheck 1.54 C/C++静态代码分析工具

cppcheck是一款强大的C/C++静态代码分析工具,版本1.54增加了对64位移植性、Boost库使用、内存泄漏、异常安全等方面的检查。它能检测出如未初始化的变量、空指针引用、边界检查错误等问题,有助于提升代码质量和安全性。
摘要由CSDN通过智能技术生成

64-bit portability

Check if there is 64-bit portability issues:

assign address to/from int/long

Auto Variables

A pointer to a variable is only valid as long as the variable is in scope. Check:

returning a pointer to auto or temporary variable

assigning address of an variable to an effective parameter of a function

returning reference to local/temporary variable

returning address of function parameter

Boost usage

Check for invalid usage of Boost:

container modification during BOOST_FOREACH

Bounds checking

out of bounds checking

Class

Check the code for each class.

Missing constructors

Are all variables initialized by the constructors?

Warn if memset, memcpy etc are used on a class

If it's a base class, check that the destructor is virtual

Are there unused private functions

'operator=' should return reference to self

'operator=' should check for assignment to self

Constness for member functions

Exception Safety

Checking exception safety

Throwing exceptions in destructors

Throwing exception during invalid state

Throwing a copy of a caught exception instead of rethrowing the original exception

exception caught by value instead of by reference

Match assignments and conditions

Match assignments and conditions:

Mismatching assignment and comparison => comparison is always true/false

Mismatching lhs and rhs in comparison => comparison is always true/false

Detect matching 'if' and 'else if' conditions

Memory leaks (address not taken)

Not taking the address to allocated memory

Memory leaks (class variables)

If the constructor allocate memory then the destructor must deallocate it.

Memory leaks (function variables)

Is there any allocated memory when a function goes out of scope

Memory leaks (struct members)

Don't forget to deallocate struct members

Non reentrant functions

Warn if any of these non reentrant functions are used:

crypt

ctermid

ecvt

fcvt

fgetgrent

fgetpwent

fgetspent

gcvt

getgrent

getgrgid

getgrnam

gethostbyaddr

gethostbyname

gethostbyname2

gethostent

getlogin

getnetbyaddr

getnetbyname

getnetgrent

getprotobyname

getpwent

getpwnam

getpwuid

getrpcbyname

getrpcbynumber

getrpcent

getservbyname

getservbyport

getservent

getspent

getspnam

gmtime

localtime

readdir

strtok

tempnam

ttyname

Null pointer

Null pointers

null pointer dereferencing

Obsolete functions

Warn if any of these obsolete functions are used:

asctime

asctime_r

bcmp

bcopy

bsd_signal

bzero

ctime

ctime_r

ecvt

fcvt

ftime

gcvt

getcontext

gethostbyaddr

gethostbyname

getwd

index

makecontext

pthread_attr_getstackaddr

pthread_attr_setstackaddr

rand_r

rindex

scalbln

swapcontext

tmpnam

tmpnam_r

ualarm

usleep

utime

vfork

wcswcs

Other

Other checks

Assigning bool value to pointer (converting bool value to address)

division with zero

using fflush() on an input stream

scoped object destroyed immediately after construction

assignment in an assert statement

sizeof for array given as function argument

sizeof for numeric given as function argument

using sizeof(pointer) instead of the size of pointed data

incorrect length arguments for 'substr' and 'strncmp'

invalid usage of output stream. For example: std::cout << std::cout;'

wrong number of arguments given to 'printf' or 'scanf;'

double free() or double closedir()

C-style pointer cast in cpp file

casting between incompatible pointer types

redundant if

bad usage of the function 'strtol'

Dangerous usage of 'scanf'

passing parameter by value

variable scope can be limited

condition that is always true/false

unusal pointer arithmetic. For example: "abc" + 'd'

redundant assignment in a switch statement

redundant strcpy in a switch statement

look for 'sizeof sizeof ..'

look for calculations inside sizeof()

assignment of a variable to itself

mutual exclusion over || always evaluating to true

Clarify calculation with parentheses

using increment on boolean

comparison of a boolean with a non-zero integer

comparison of a boolean expression with an integer other than 0 or 1

suspicious condition (assignment+comparison)

suspicious condition (runtime comparison of string literals)

suspicious condition (string literals as boolean)

duplicate break statement

unreachable code

testing if unsigned variable is negative

testing is unsigned variable is positive

using bool in bitwise expression

Suspicious use of ; at the end of 'if/for/while' statement.

incorrect usage of functions from ctype library.

optimisation: detect post increment/decrement

STL usage

Check for invalid usage of STL:

out of bounds errors

misuse of iterators when iterating through a container

mismatching containers in calls

dereferencing an erased iterator

for vectors: using iterator/pointer after push_back has been used

optimisation: use empty() instead of size() to guarantee fast code

suspicious condition when using find

redundant condition

common mistakes when using string::c_str()

using auto pointer (auto_ptr)

useless calls of string functions

Uninitialized variables

Uninitialized variables

using uninitialized variables and data

Unused functions

Check for functions that are never called

UnusedVar

UnusedVar checks

unused variable

allocated but unused variable

unred variable

unassigned variable

unused struct member

Using postfix operators

Warn if using postfix operators ++ or -- rather than prefix operator

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值