Programming Search⌘K

C lints

The lint rules of C, with what each one finds. This page has 78 cards.

Check for returned pointers and references that are bound to an object whose lifetime ends when the function returns. alpha.core.UseAfterLifetimeEnd

The checker only analyzes code that is annotated with the [[clang::lifetimebound]] attribute. The annotation tells the checker which object the returned value is bound to. It is an experimental (alpha) checker, so the analyzer does not run it by default. It applies to C, C++.

Code
alpha.core.UseAfterLifetimeEnd

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

Simple lock -> unlock checker. alpha.unix.PthreadLock

Applies to: pthread_mutex_lock, pthread_rwlock_rdlock, pthread_rwlock_wrlock, lck_mtx_lock, lck_rw_lock_exclusive lck_rw_lock_shared, pthread_mutex_trylock, pthread_rwlock_tryrdlock, pthread_rwlock_tryrwlock, lck_mtx_try_lock, lck_rw_try_lock_exclusive, lck_rw_try_lock_shared, pthread_mutex_unlock, pthread_rwlock_unlock, lck_mtx_unlock, lck_rw_done. It is an experimental (alpha) checker, so the analyzer does not run it by default. It applies to C.

Code
alpha.unix.PthreadLock

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

Check for integer to enumeration casts that would produce a value with no corresponding enumerator. optin.core.EnumCastOutOfRange

This is not necessarily undefined behavior, but can lead to nasty surprises, so projects may decide to use a coding standard that disallows these "unusual" conversions. It is an opt-in checker, so the analyzer runs it only when you enable it. clang-tidy runs it as the check clang-analyzer-optin.core.EnumCastOutOfRange. It applies to C, C++.

Code
optin.core.EnumCastOutOfRange

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

Check for variadic functions that unconditionally use va_arg(). optin.core.UnconditionalVAArg

It is possible to use such functions safely (as long as they always receive at least one variadic argument), but their careless use can lead to undefined behavior (trying to access a variadic argument when there isn't any), so it is better to avoid them. It is an opt-in checker, so the analyzer runs it only when you enable it. clang-tidy runs it as the check clang-analyzer-optin.core.UnconditionalVAArg. It applies to C, C++.

Code
optin.core.UnconditionalVAArg

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

Taint analysis identifies potential security vulnerabilities where the attacker can inject malicious data to the program to execute an attack (privilege escalation, command injection, SQL injection etc.). optin.taint.GenericTaint

It is an opt-in checker, so the analyzer runs it only when you enable it. clang-tidy runs it as the check clang-analyzer-optin.taint.GenericTaint. It applies to C, C++.

Code
optin.taint.GenericTaint

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

This checker warns for cases when the size parameter of the malloc , calloc, realloc, alloca or the size parameter of the array new C++ operator is tainted (potentially attacker controlled). optin.taint.TaintedAlloc

If an attacker can inject a large value as the size parameter, memory exhaustion denial of service attack can be carried out. It is an opt-in checker, so the analyzer runs it only when you enable it. clang-tidy runs it as the check clang-analyzer-optin.taint.TaintedAlloc. It applies to C, C++.

Code
optin.taint.TaintedAlloc

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

This checker warns when the denominator in a division operation is a tainted (potentially attacker controlled) value. optin.taint.TaintedDiv

If the attacker can set the denominator to 0, a runtime error can be triggered. The checker warns when the denominator is a tainted value and the analyzer cannot prove that it is not 0. It is an opt-in checker, so the analyzer runs it only when you enable it. clang-tidy runs it as the check clang-analyzer-optin.taint.TaintedDiv. It applies to C, C++, Objective-C.

Code
optin.taint.TaintedDiv

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

Check for pointer subtractions on two pointers pointing to different memory chunks. security.PointerSub

According to the C standard §6.5.6 only subtraction of pointers that point into (or one past the end) the same array object is valid (for this purpose non-array variables are like arrays of size 1). This checker only searches for different memory objects at subtraction, but does not check if the array index is correct. clang-tidy runs it as the check clang-analyzer-security.PointerSub. It applies to C.

Code
security.PointerSub

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

Finds calls to the putenv function which pass a pointer to a stack-allocated (automatic) array as the argument. security.PutenvStackArray

Function putenv does not copy the passed string, only a pointer to the data is stored and this data can be read even by other threads. Content of a stack-allocated array is likely to be overwritten after exiting from the function. clang-tidy runs it as the check clang-analyzer-security.PutenvStackArray. It applies to C.

Code
security.PutenvStackArray

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

Check for calls to blocking functions inside a critical section. unix.BlockInCriticalSection

Blocking functions detected by this checker: sleep, getc, fgets, read, recv. Critical section handling functions modeled by this checker: lock, unlock, pthread_mutex_lock, pthread_mutex_trylock, pthread_mutex_unlock, mtx_lock, mtx_timedlock, mtx_trylock, mtx_unlock, lock_guard, unique_lock, scoped_lock. clang-tidy runs it as the check clang-analyzer-unix.BlockInCriticalSection. It applies to C, C++.

Code
unix.BlockInCriticalSection

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

Check for improper use of errno. unix.Errno

This checker implements partially CERT rule ERR30-C. Set errno to zero before calling a library function known to set errno, and check errno only after the function returns a value indicating failure. The checker can find the first read of errno after successful standard function calls. clang-tidy runs it as the check clang-analyzer-unix.Errno. It applies to C.

Code
unix.Errno

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

Check for calls of standard library functions that violate predefined argument constraints. unix.StdCLibraryFunctions

For example, according to the C standard the behavior of function int isalnum(int ch) is undefined if the value of ch is not representable as unsigned char and is not equal to EOF. clang-tidy runs it as the check clang-analyzer-unix.StdCLibraryFunctions. It applies to C.

Code
unix.StdCLibraryFunctions

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.