C++ rules
tx0 checks .cpp, .cc, .cxx, .hpp, .hh and .hxx files with 291 rules, 92 of them in the default tier. Files that say a tool generated them are skipped. Each rule's page explains what it finds and what it leaves alone.
Default: 92 rules
Bugs and security problems with measured precision. They run without a tx0.toml.
-
tx0/cpp:accumulate-truncates-to-integerdefaultstd::accumulateover floating values starts from an integer literal, so every partial sum is converted to an integer -
tx0/cpp:assert-always-truedefaultassertis given a string literal alone, which is a non-null pointer and never fails -
tx0/cpp:async-result-discardeddefaultThe future that
std::asyncreturns is dropped, and its destructor waits for the task, so the call runs synchronously -
tx0/cpp:atomic-read-modify-write-splitdefaultAn atomic variable is updated with
x = x + ..., a separate load and store that other threads can interleave -
tx0/cpp:auto-ptrdefaultstd::auto_ptris used, whose copies silently transfer ownership and which C++17 removed -
tx0/cpp:bitwise-precedencedefaultA comparison is an operand of a bitwise operator without parentheses
-
tx0/cpp:bool-incrementdefaultA
boolvariable is incremented or decremented, which C++17 removed and which never meant counting -
tx0/cpp:chained-comparisondefaultRelational comparisons are chained, as in
a < b < c, which compares theboolresult of the first with the third -
tx0/cpp:char-compared-with-eofdefaultA
charvariable is compared withEOF, which acharcannot tell apart from a real character -
tx0/cpp:check-after-dereferencedefaultA pointer is tested for NULL after it was already dereferenced
-
tx0/cpp:comparison-result-as-onedefaultThe result of
strcmpormemcmpis compared with 1 or -1, though only its sign is defined -
tx0/cpp:constant-index-out-of-boundsdefaultAn array is indexed with a constant outside its bounds
-
tx0/cpp:constant-overflowdefaultArithmetic on
intconstants overflows the range ofint -
tx0/cpp:constant-size-exceeds-arraydefaultA constant size given with an array is larger than the array
-
tx0/cpp:continue-in-do-while-falsedefaultcontinueinsidedo { ... } while (false)jumps to the condition, which ends the loop, so it acts asbreak -
tx0/cpp:copy-onto-itselfdefaultA buffer is copied onto itself with a function that requires them apart
-
tx0/cpp:delete-form-mismatchdefaultMemory from
new[]is freed withdelete, or memory fromnewwithdelete[] -
tx0/cpp:delete-of-smart-pointer-getdefaultThe pointer from
get()of a smart pointer is deleted, and the smart pointer deletes it again -
tx0/cpp:delete-void-pointerdefaultA
void *is deleted, which is undefined behaviour and runs no destructor -
tx0/cpp:discarded-allocationdefaultThe result of a function that allocates is discarded, so it can never be released
-
tx0/cpp:division-by-zerodefaultAn integer is divided by a constant zero
-
tx0/cpp:double-closedefaultA stream or directory is closed twice
-
tx0/cpp:double-freedefaultMemory is freed twice
-
tx0/cpp:duplicate-casedefaultTwo case labels have the same value
-
tx0/cpp:duplicate-conditiondefaultA condition of an if-else chain repeats an earlier one
-
tx0/cpp:empty-if-bodydefaultA semicolon right after the condition of an
ifis its whole body -
tx0/cpp:empty-loop-bodydefaultA semicolon right after the head of a loop is its whole body, and the block after it runs once
-
tx0/cpp:empty-result-discardeddefaultThe result of
empty()is dropped, though the call only tests the container and changes nothing -
tx0/cpp:erase-one-after-removedefaulteraseis given only the result ofstd::remove, so it erases one element instead of the removed ones -
tx0/cpp:exception-not-throwndefaultAn exception object is constructed as a statement of its own and dropped, where
throwwas probably meant -
tx0/cpp:expression-without-effectdefaultAn expression statement computes a value and throws it away
-
tx0/cpp:format-argumentsdefaultA format string of
printfand its arguments do not match -
tx0/cpp:free-non-heapdefaultfreeis given memory that was not allocated on the heap -
tx0/cpp:free-pointer-offsetdefaultfreeis given a pointer computed by adding to or subtracting from another pointer -
tx0/cpp:getsdefaultgetsis called -
tx0/cpp:getwddefaultgetwdis called -
tx0/cpp:identical-operandsdefaultBoth operands of an operator are the same
-
tx0/cpp:insecure-temporary-filedefaultA temporary file name is made with a function that leaves time for another process to take the name
-
tx0/cpp:iterators-of-different-containersdefaultAn algorithm gets the begin of one container and the end of another as its range
-
tx0/cpp:loop-condition-never-changesdefaultThe condition of a
whileloop compares local variables that the loop never changes, so it runs forever or not at all -
tx0/cpp:loop-past-array-enddefaultA loop over an array runs one step past its end because its condition uses
<= -
tx0/cpp:member-delete-form-mismatchdefaultA destructor frees a member made with
new[]usingdelete, or one made withnewusingdelete[] -
tx0/cpp:memset-on-class-objectdefaultmemset,memcpyormemmovewrites over an object of a class with virtual functions or with string or container members -
tx0/cpp:memset-swappeddefaultmemsetis called with a length of zero, its last two arguments swapped -
tx0/cpp:memset-value-truncateddefaultmemsetis given a fill value that does not fit in a byte -
tx0/cpp:misleading-indentationdefaultA statement is indented as if it belonged to the body of an
ifor loop without braces, but runs after it -
tx0/cpp:move-result-discardeddefaultstd::move(x)stands alone as a statement and has no effect -
tx0/cpp:nested-sizeofdefaultsizeofis applied to the result of anothersizeof -
tx0/cpp:null-dereferencedefaultA pointer is dereferenced where it is NULL on every path
-
tx0/cpp:open-create-without-modedefaultopenis asked to create a file but is not given the permissions for it -
tx0/cpp:pointer-into-temporary-stringdefaultA pointer from
c_str()ordata()of a temporary string is kept, and the string is destroyed at the end of the statement -
tx0/cpp:pointer-to-local-string-returneddefaultA function returns
c_str(),data()or a view of a local string or vector, which is destroyed on return -
tx0/cpp:posix-error-compared-negativedefaultThe result of a
pthread_orposix_function is tested for a negative value, which these functions never return -
tx0/cpp:release-mismatchdefaultA resource is released with the function for another kind of resource
-
tx0/cpp:remainder-by-onedefaultThe remainder of a division by one is taken, which is always zero
-
tx0/cpp:remove-without-erasedefaultstd::remove,std::remove_iforstd::uniqueis called for its effect, which leaves the container's size unchanged -
tx0/cpp:rethrow-copydefaultA handler throws the exception it caught by name, which throws a copy of its static type instead of the original
-
tx0/cpp:return-freed-pointerdefaultA function returns a pointer to memory it has freed
-
tx0/cpp:return-local-addressdefaultA function returns the address of one of its local variables
-
tx0/cpp:reversed-compound-assignmentdefaultAn assignment is written
=+or=-where+=or-=was probably meant -
tx0/cpp:scanf-unbounded-stringdefaultscanfreads a string into a buffer with no limit on its length -
tx0/cpp:self-assignmentdefaultA value is assigned to itself
-
tx0/cpp:self-movedefaultA variable is assigned
std::moveof itself, which may leave it empty -
tx0/cpp:shift-rangedefaultA shift count is negative or not less than the width of the value
-
tx0/cpp:sizeof-array-parameterdefaultsizeofis applied to a parameter declared as an array, which is a pointer -
tx0/cpp:sizeof-pointer-allocationdefaultMemory for what a pointer points to is allocated with the size of the pointer itself
-
tx0/cpp:sizeof-pointer-lengthdefaultThe length passed with a buffer is the size of the pointer to it
-
tx0/cpp:smart-pointer-array-mismatchdefaultA
std::unique_ptrorstd::shared_ptrof a single object takes an array made withnew[], and frees it withdelete -
tx0/cpp:smart-pointer-from-getdefaultA smart pointer is initialized with
get()of another smart pointer, so two owners delete the same object -
tx0/cpp:smart-pointer-to-localdefaultA smart pointer takes the address of a local variable, and deletes memory that
newdid not allocate -
tx0/cpp:sprintf-reads-destinationdefaultsprintfreads from the buffer it writes to -
tx0/cpp:string-compared-with-nulldefaultA
std::stringis compared withnullptr,NULLor0, which constructs a string from a null pointer -
tx0/cpp:string-comparisondefaultStrings are compared with
==or!=, which compares their addresses -
tx0/cpp:string-constructor-arguments-swappeddefaultA
std::stringis constructed with a character and then a number, which repeats the number's character instead -
tx0/cpp:string-find-as-conditiondefaultThe result of a string's
findis used as a condition, which is true when the text is missing and false when it is at the start -
tx0/cpp:string-from-nulldefaultA
std::stringis constructed from0,NULLornullptr, which is undefined behaviour -
tx0/cpp:string-literal-plus-integerdefaultAn integer is added to a string literal, which moves the pointer into the literal instead of appending a number
-
tx0/cpp:string-literal-writedefaultMemory of a string literal is written through a pointer to it
-
tx0/cpp:strncat-sizedefaultstrncatis given the size of its destination as the number of characters to append -
tx0/cpp:this-compared-with-nulldefaultthisis compared with null, which the compiler may assume false since calling a member through a null pointer is undefined -
tx0/cpp:thread-never-joineddefaultA local
std::threadis neither joined nor detached, and its destructor ends the program -
tx0/cpp:throw-in-destructordefaultA destructor throws an exception that leaves it, which ends the program since destructors are
noexcept -
tx0/cpp:throw-in-noexceptdefaultA function declared
noexceptthrows an exception that leaves it, which callsstd::terminate -
tx0/cpp:throw-newdefaultAn exception is thrown as a pointer made with
new, which handlers for the type do not catch -
tx0/cpp:uninitialized-readdefaultA local variable is read before any value is assigned to it
-
tx0/cpp:unnamed-lockdefaultA lock object is created as a temporary, which unlocks again at the end of the statement
-
tx0/cpp:unreachable-handlerdefaultAn exception handler comes after a handler for one of its base classes, which catches everything it would
-
tx0/cpp:unsequenced-modificationdefaultA variable is changed twice, or changed and read, in one expression without a sequence point between
-
tx0/cpp:unsigned-zero-comparisondefaultAn unsigned value is tested for being negative
-
tx0/cpp:use-after-closedefaultA stream or directory is used after it was closed
-
tx0/cpp:use-after-freedefaultMemory is used through a pointer after the pointer was freed
-
tx0/cpp:view-of-temporary-stringdefaultA
std::string_viewis initialized from a temporary string, which is destroyed at the end of the statement
Recommended: 87 rules
Likely bugs, resource and performance problems.
-
tx0/cpp:alloca-callrecommendedMemory is taken from the stack with
alloca, which cannot report failure -
tx0/cpp:allocation-function-without-pairrecommendedA class or file defines
operator newwithout the matchingoperator delete, or the other way round -
tx0/cpp:anonymous-namespace-in-headerrecommendedA header has an unnamed namespace, which gives every file that includes it a copy of its contents
-
tx0/cpp:array-drops-terminatorrecommendedA character array is initialized with a string exactly as long as the array, leaving out the terminating zero
-
tx0/cpp:assert-side-effectrecommendedThe condition of
assertchanges a variable, which does not happen when assertions are off -
tx0/cpp:assignment-in-conditionrecommendedA condition is an assignment without parentheses that mark it as meant
-
tx0/cpp:assignment-operator-return-typerecommendedAn assignment operator returns something other than a reference to its class
-
tx0/cpp:catch-by-valuerecommendedAn exception of a class type is caught by value, which copies it and cuts off the parts of derived classes
-
tx0/cpp:check-then-openrecommendedA file is checked with
accessand opened by name afterwards, so it may have changed in between -
tx0/cpp:chroot-without-chdirrecommendedchrootis called without achdirafter it, so the working directory stays outside the jail -
tx0/cpp:comparator-not-strictrecommendedA comparison given to a sorting algorithm uses
<=or>=, which is no strict ordering -
tx0/cpp:condition-wait-without-predicaterecommendedA condition variable is waited on without a predicate or loop, so spurious and missed wake-ups go unnoticed
-
tx0/cpp:constant-assignment-conditionrecommendedA condition assigns a constant where a comparison was meant
-
tx0/cpp:container-changed-in-range-forrecommendedA range
foradds or removes elements of the container it iterates, which invalidates its iterators -
tx0/cpp:copy-constructor-skips-baserecommendedA copy constructor of a derived class does not copy its base class, which is default-constructed instead
-
tx0/cpp:declaration-in-namespace-stdrecommendedA file declares something new in namespace
std, which the standard makes undefined behaviour -
tx0/cpp:detached-thread-captures-by-referencerecommendedA thread that is detached runs a lambda capturing by reference, which may outlive the variables it refers to
-
tx0/cpp:duplicate-includerecommendedA header is included twice in the same file
-
tx0/cpp:dynamic-exception-specificationrecommendedA function declares the exceptions it throws with
throw(...), a form later standards removed -
tx0/cpp:empty-catchrecommendedAn exception handler has an empty body and no comment, so the error disappears without a trace
-
tx0/cpp:erase-invalidates-loop-iteratorrecommendedA loop erases the element its iterator points to and then increments that iterator, which is no longer valid
-
tx0/cpp:erased-before-freerecommendedMemory is cleared with
memsetright before it is freed, which the compiler may drop -
tx0/cpp:errno-not-clearedrecommendederrnois tested after a conversion function without being set to zero before the call -
tx0/cpp:fallthroughrecommendedA case of a switch falls through into the next one without saying so
-
tx0/cpp:feof-looprecommendedA loop tests
feofbefore reading, so it runs once more after the last read fails -
tx0/cpp:floating-loop-counterrecommendedA loop counts with a floating variable, so rounding changes how often it runs
-
tx0/cpp:format-from-variablerecommendedA variable is used as the format of
printfwithout other arguments -
tx0/cpp:function-name-in-lambdarecommended__func__or__FUNCTION__is used inside a lambda, where it names the lambda's call operator and not the enclosing function -
tx0/cpp:hardcoded-passwordrecommendedA password or secret is written into the source as a string literal
-
tx0/cpp:heavy-parameter-copiedrecommendedA string or container parameter is taken by value and only read, so every call copies it for nothing
-
tx0/cpp:hex-escape-swallows-digitsrecommendedA hexadecimal escape in a string takes in the first letters of the word after it
-
tx0/cpp:identical-branchesrecommendedBoth branches of an if-else or a conditional expression are the same
-
tx0/cpp:ignored-privilege-changerecommendedThe result of a call that drops privileges is ignored, so a failure leaves them in place
-
tx0/cpp:impossible-conditionrecommendedTwo comparisons of the same value with constants make a condition that is always false or always true
-
tx0/cpp:integer-division-to-floatingrecommendedAn integer division is stored in a floating variable, after its fraction is already lost
-
tx0/cpp:internal-library-headerrecommendedA file includes a header from the
bits/directory of a standard library implementation, as<bits/stdc++.h> -
tx0/cpp:lambda-returned-with-reference-capturesrecommendedA function returns a lambda that captures its locals or parameters by reference, which dangle once it returns
-
tx0/cpp:leak-on-early-returnrecommendedA function returns without freeing memory it allocated and still holds only in a local variable
-
tx0/cpp:local-mutexrecommendedA mutex is a local variable of the function that locks it, so each call locks its own mutex and nothing is protected
-
tx0/cpp:loop-variable-too-smallrecommendedA loop counter of type
charorshortis compared with a wider bound, so it may wrap around before reaching it -
tx0/cpp:malloc-strlenrecommendedMemory for a copy of a string is allocated without room for its terminating zero
-
tx0/cpp:member-initializer-orderrecommendedThe member initializers of a constructor are written in another order than the members are declared, which is the order that runs
-
tx0/cpp:missing-return-valuerecommendedA function that returns a value can reach its end without a return statement
-
tx0/cpp:move-of-constrecommendedstd::moveis applied to aconstobject, which cannot be moved from and is copied instead -
tx0/cpp:move-of-forwarding-referencerecommendedA forwarding reference is passed on with
std::move, which moves from lvalues the caller still owns -
tx0/cpp:move-operation-without-noexceptrecommendedA move constructor or move assignment is not
noexcept, so containers copy elements instead of moving them -
tx0/cpp:not-precedencerecommendedA negation with
!is compared with a value that is not a truth value -
tx0/cpp:null-check-after-newrecommendedThe result of
newis compared with null, which never holds sincenewthrows on failure -
tx0/cpp:override-not-markedrecommendedA member function overrides a virtual function of a base class in the file without saying
override -
tx0/cpp:polymorphic-parameter-by-valuerecommendedA parameter of a class type with virtual functions is taken by value, which slices objects of derived classes
-
tx0/cpp:predictable-random-secretrecommendedA value that looks like a secret is made with
rand, whose output can be predicted -
tx0/cpp:printf-writes-countrecommendedA format of
printfhas the%nconversion, which writes to memory -
tx0/cpp:putenv-local-bufferrecommendedputenvis given a local array, which the environment keeps using after the function returns -
tx0/cpp:random-seeded-with-timerecommendedA random generator is seeded with the current time, which anyone can guess
-
tx0/cpp:range-for-copies-elementrecommendedA range
forcopies each string or container element into a loop variable that is only read -
tx0/cpp:realloc-same-pointerrecommendedThe result of
reallocis assigned to the pointer it was given, which is lost if it fails -
tx0/cpp:reference-to-local-returnedrecommendedA function that returns a reference returns a local variable or by-value parameter, which is destroyed when the function returns
-
tx0/cpp:removed-library-functionrecommendedA function or class template is used that C++17 removed from the standard library
-
tx0/cpp:return-std-moverecommendedA local variable or by-value parameter is returned through
std::move, which prevents copy elision -
tx0/cpp:shared-ptr-from-thisrecommendedA
std::shared_ptris created fromthis, which starts a second, independent owner count for the object -
tx0/cpp:shell-command-from-variablerecommendedA shell command is run from a string that is not a literal
-
tx0/cpp:signed-one-bit-fieldrecommendedA bit-field of one bit has a signed type, so it holds 0 and -1 rather than 0 and 1
-
tx0/cpp:sizeof-containerrecommendedsizeofis applied to a standard container or string, which gives the size of the object and not of its elements -
tx0/cpp:smart-pointer-of-c-allocationrecommendedA smart pointer without a deleter owns memory or a stream from the C library, which it releases with
delete -
tx0/cpp:source-file-includedrecommendedA source file is included with
#include, as"parser.cpp" -
tx0/cpp:sscanf-unbounded-stringrecommendedsscanfcopies a word of its input into a buffer with no limit on its length -
tx0/cpp:string-list-missing-commarecommendedTwo string literals in a list of strings are joined into one element, probably for want of a comma
-
tx0/cpp:string-position-in-intrecommendedThe result of a string's
findis stored in anintorunsigned, which cannot holdnposand truncates large positions -
tx0/cpp:strncmp-short-lengthrecommendedstrncmpcompares fewer characters than the string literal it is given has -
tx0/cpp:strncpy-source-lengthrecommendedThe limit of
strncpyis the length of its source -
tx0/cpp:switch-misses-enumeratorrecommendedA
switchover a scoped enumeration of the file has nodefaultand leaves out some of its enumerators -
tx0/cpp:throw-literalrecommendedA number, character or string literal is thrown instead of an exception object
-
tx0/cpp:tls-verification-disabledrecommendedThe verification of TLS certificates is turned off
-
tx0/cpp:unchecked-allocation-userecommendedMemory from
mallocis used right away without a test that the allocation succeeded -
tx0/cpp:unique-ptr-release-discardedrecommendedThe pointer that
release()of astd::unique_ptrreturns is dropped, and the object is never deleted -
tx0/cpp:unreachable-coderecommendedA statement follows a
return,break,continueorgotoin the same block and never runs -
tx0/cpp:unused-labelrecommendedA label is never the target of a
goto -
tx0/cpp:unused-lambda-capturerecommendedA lambda captures a variable by name that its body never uses
-
tx0/cpp:use-after-moverecommendedA local variable is read after it was passed to
std::move, when its value is unspecified -
tx0/cpp:using-namespace-in-headerrecommendedA header says
using namespaceoutside any function, which brings the names into every file that includes it -
tx0/cpp:variable-length-arrayrecommendedA local array has a length that is only known at run time, which standard C++ does not allow
-
tx0/cpp:virtual-call-in-constructorrecommendedA constructor or destructor calls a virtual function of its class, which runs the class's own version and never an override
-
tx0/cpp:virtual-default-argumentrecommendedA virtual function has default arguments, which come from the static type of the call and not from the override that runs
-
tx0/cpp:virtual-functions-without-virtual-destructorrecommendedA class with virtual functions has a public destructor that is not virtual, so deleting through a base pointer skips the derived destructor
-
tx0/cpp:void-mainrecommendedmainis defined to returnvoidinstead ofint -
tx0/cpp:weak-cryptographyrecommendedA hash or cipher that is broken for security purposes is used
-
tx0/cpp:world-writable-moderecommendedA file is given permissions that let every user write to it
Strict: 75 rules
Code that can be written more plainly.
-
tx0/cpp:allocation-size-productstrictThe size given to
mallocorreallocis a product that may overflow unchecked -
tx0/cpp:auto-from-brace-liststrictA variable declared
autois initialized with= {...}, which makes it astd::initializer_list -
tx0/cpp:c-memory-managementstrictMemory is managed with
malloc,calloc,reallocorfree, which do not run constructors or destructors -
tx0/cpp:c-random-generatorstrictRandom numbers come from
rand, whose quality and range are poor and whose state is shared -
tx0/cpp:c-style-caststrictA value is converted with a C-style cast, which may do a
reinterpret_castor removeconstwithout saying so -
tx0/cpp:catch-only-rethrowsstrictEvery handler of a
tryonly rethrows, so thetryhas no effect -
tx0/cpp:comma-in-conditionstrictThe condition of an
ifor loop is a comma expression, so only its last part decides -
tx0/cpp:const-caststrictconst_castremovesconstorvolatilefrom a value -
tx0/cpp:const-value-returnstrictA function returns a class object by
constvalue, which stops the caller from moving from it -
tx0/cpp:constant-if-conditionstrictThe condition of an
ifis a constant, so one branch never runs -
tx0/cpp:copy-assignment-not-self-safestrictA copy assignment operator deletes a member before it reads the source, which is the same object on self-assignment
-
tx0/cpp:ctype-plain-charstrictA plain
charis passed to a function ofctype.h, which is undefined for negative values -
tx0/cpp:destructor-without-copy-operationsstrictA class defines a destructor but neither declares nor deletes its copy constructor and copy assignment
-
tx0/cpp:double-checked-lock-not-atomicstrictA variable is tested before and after taking a lock, and the first test reads it without the lock and without
std::atomic -
tx0/cpp:element-reference-after-growthstrictA reference, pointer or iterator into a vector or string is used after the container may have reallocated
-
tx0/cpp:emplace-of-temporarystrictemplace_backoremplaceis given a pair or tuple built in place, which constructs a temporary and moves it -
tx0/cpp:empty-blockstrictThe body of an
if,elseor loop is an empty block without a comment -
tx0/cpp:exit-skips-destructorsstrictThe program ends with
exitorquick_exit, which skip the destructors of local objects -
tx0/cpp:find-with-one-character-stringstrictA string is searched for a string literal of one character, where the character itself is faster
-
tx0/cpp:floating-equalitystrictFloating values are compared for exact equality
-
tx0/cpp:function-like-macrostrictA function-like macro is defined, where an inline function or template would check its arguments and evaluate them once
-
tx0/cpp:generic-exception-thrownstrictstd::exceptionitself is thrown, which carries no message and no type a handler can tell apart -
tx0/cpp:goto-into-blockstrictA
gotojumps into a block past declarations that initialize variables -
tx0/cpp:goto-statementstrictA function jumps with
goto -
tx0/cpp:implicit-conversion-operatorstrictA conversion operator is not
explicit, so objects convert to its type wherever a conversion fits -
tx0/cpp:implicit-converting-constructorstrictA constructor that takes one argument is not
explicit, so it converts implicitly -
tx0/cpp:impossible-mask-comparisonstrictThe result of
&or|with a constant is compared with a value it can never equal -
tx0/cpp:index-after-reservestrictAn empty vector is indexed after
reserve, which allocates memory but adds no elements -
tx0/cpp:lambda-default-capturestrictA lambda captures by default with
[=]or[&], which hides what it depends on -
tx0/cpp:linear-search-in-associative-containerstrictstd::findorstd::countwalks a set or map element by element, where its member function searches by key -
tx0/cpp:local-address-in-globalstrictThe address of a local variable is stored in a global variable, where it outlives the variable
-
tx0/cpp:logical-operator-with-constantstrict&&or||has an integer literal other than 0 or 1 as an operand, where a bitwise operator was likely meant -
tx0/cpp:loop-counter-assignedstrictThe counter of a
forloop is also changed in the body of the loop -
tx0/cpp:macro-body-unparenthesizedstrictA macro that stands for an expression with an operator has no parentheses around it
-
tx0/cpp:macro-for-constantstrictA macro stands for a number or string, where a
constexprvariable would have a type and a scope -
tx0/cpp:macro-parameter-unparenthesizedstrictA parameter of a macro is used next to an operator without parentheses around it
-
tx0/cpp:manual-mutex-lockingstrictA function calls
lock()andunlock()on a mutex itself, which leaves it locked when an exception or early return comes between -
tx0/cpp:maybe-uninitialized-readstrictA local variable is read where some path to the read never assigned it
-
tx0/cpp:missing-include-guardstrictA header has no include guard and no
#pragma once -
tx0/cpp:multiple-inheritancestrictA class derives from more than one base class
-
tx0/cpp:mutable-global-variablestrictA variable at namespace scope is not
const, so any code in the program can change it -
tx0/cpp:mutex-locked-twicestrictA mutex that is not recursive is locked again by the thread that holds it
-
tx0/cpp:negative-left-shiftstrictA negative value is shifted left
-
tx0/cpp:nested-conditionalstrictA conditional expression is nested in another one
-
tx0/cpp:non-reentrant-functionstrictA library function that returns a pointer to shared static storage is called
-
tx0/cpp:null-on-some-pathstrictA pointer that a test found NULL on some path is dereferenced on that path
-
tx0/cpp:overflow-check-relies-on-wrapstrictAn overflow is tested by comparing
a + bwitha, which relies on wrapping that signed integers and pointers do not do -
tx0/cpp:overloaded-logical-operatorstrictoperator&&,operator||oroperator,is overloaded, which loses the evaluation order and short-circuiting of the built-in operator -
tx0/cpp:owning-raw-pointerstrictA variable of raw pointer type is initialized with
new, so the code has to remember to delete it -
tx0/cpp:postfix-increment-of-iteratorstrictThe step of a
forloop increments an iterator withit++, which copies the iterator for a value nobody uses -
tx0/cpp:printf-style-outputstrictText is formatted with
printfor a relative, whose arguments the compiler does not match against the format -
tx0/cpp:protected-data-memberstrictA class has data members that are
protected, which every derived class can change -
tx0/cpp:redundant-c-str-copystrictA
std::stringis built fromc_str()of another string, which measures it again and drops the length -
tx0/cpp:reference-to-temporary-from-min-maxstrictA reference is bound to the result of
std::min,std::maxorstd::clampwith a temporary argument -
tx0/cpp:reinterpret-caststrictA value is converted with
reinterpret_cast, which reads its bits as another type -
tx0/cpp:reserved-identifierstrictA declared name or macro starts with two underscores or an underscore and a capital letter, which the implementation reserves
-
tx0/cpp:self-initializationstrictA variable is initialized with its own value, which is indeterminate at that point
-
tx0/cpp:setjmp-longjmpstrictControl is transferred with
setjmpandlongjmp -
tx0/cpp:shadowed-variablestrictA local variable has the name of a variable or parameter of an enclosing scope in the same function
-
tx0/cpp:shift-into-sign-bitstrictA constant
intis shifted left into or past its sign bit -
tx0/cpp:sizeof-division-mismatchstrictThe size of one array is divided by the size of an element of another array
-
tx0/cpp:stream-endlstrictstd::endlends a line in a stream and also flushes it, which is slow when done for every line -
tx0/cpp:stream-not-closedstrictA function returns while a stream or directory it opened is still open
-
tx0/cpp:string-append-by-concatenationstrictA string is extended with
s = s + x, which builds a new string and copiessinto it -
tx0/cpp:string-literal-pointerstrictA pointer to non-const
charis made to point to a string literal -
tx0/cpp:strlen-in-loop-conditionstrictThe condition of a loop calls
strlenon a string the loop does not change, once per step -
tx0/cpp:strlen-of-c-strstrictstrlenmeasuresc_str()of a string, whose length the string already knows -
tx0/cpp:switch-without-defaultstrictA
switchhas nodefaultcase -
tx0/cpp:unbounded-sprintfstrictsprintfwrites formatted text into a buffer whose size it does not know -
tx0/cpp:unbounded-string-copystrictA string is copied or appended with a function that does not know the size of the destination
-
tx0/cpp:unchecked-number-parsestrictA number is parsed with
atoioratof, which cannot report invalid input -
tx0/cpp:unscoped-enumstrictA named enumeration is not scoped, so its enumerators enter the surrounding scope and convert to integers
-
tx0/cpp:unused-local-variablestrictA local variable is declared but never used
-
tx0/cpp:unused-parameterstrictA named parameter of a function definition is never used in its body
-
tx0/cpp:unused-static-functionstrictA
staticfunction is defined but never used in its file
: 37 rules
-
tx0/cpp:boolean-expression-complexityallA condition joins more
&&and||operators than the configured maximum -
tx0/cpp:boolean-literal-comparisonallA value is compared with
trueorfalse -
tx0/cpp:c-library-headerallA C library header is included by its C name, as
<stdio.h>, instead of the C++ form<cstdio> -
tx0/cpp:class-member-countallA class declares more member functions than the limit, which suggests it does several jobs
-
tx0/cpp:collapsible-ifallAn
ifwithoutelseholds only anotherifwithoutelse, which could be one condition -
tx0/cpp:commented-out-codeallA comment holds code that was switched off
-
tx0/cpp:const-value-parameter-in-declarationallA function declaration that is not a definition marks a by-value parameter
const, which means nothing to callers -
tx0/cpp:count-for-membershipallMembership in a map or set is tested with
count, wherecontainssays it directly -
tx0/cpp:cyclomatic-complexityallA function has more independent paths than the configured maximum
-
tx0/cpp:default-not-lastallThe
defaultcase of aswitchis not its last case -
tx0/cpp:else-after-jumpallAn
elsefollows a branch that always returns or jumps -
tx0/cpp:empty-default-constructorallA default constructor has an empty body and no initializers, which
= defaultsays more plainly -
tx0/cpp:empty-destructorallA destructor has an empty body, which
= defaultsays more plainly -
tx0/cpp:empty-string-initializerallA
std::stringis initialized with"", which the default constructor already gives -
tx0/cpp:file-lengthallA file has more lines of code than the configured maximum
-
tx0/cpp:function-lengthallA function body has more lines of code than the configured maximum
-
tx0/cpp:inline-member-definitionallA member function defined in its class body says
inline, which it is already -
tx0/cpp:lambda-lengthallA lambda's body is longer than the limit, which hides a function inside an expression
-
tx0/cpp:lowercase-long-suffixallA literal has the suffix
l, which looks like the digit1 -
tx0/cpp:mixed-declaratorsallOne declaration declares pointers and non-pointers together
-
tx0/cpp:nesting-depthallControl statements are nested deeper than the configured maximum
-
tx0/cpp:null-check-before-deleteallA pointer is tested for null before
delete, which accepts null already -
tx0/cpp:null-macroallThe macro
NULLis used as a null pointer, wherenullptrhas a pointer type -
tx0/cpp:parameter-countallA function takes more parameters than the configured maximum
-
tx0/cpp:redundant-boolean-conditionalallA conditional expression chooses between
trueandfalse -
tx0/cpp:register-storageallA local variable is declared
register -
tx0/cpp:return-countallA function has more
returnstatements than the configured maximum -
tx0/cpp:size-compared-with-zeroallA container's
size()orlength()is compared with zero, whereempty()says the same directly -
tx0/cpp:smart-pointer-from-newallA
std::unique_ptrorstd::shared_ptris initialized withnew, wherestd::make_uniqueorstd::make_sharedsays it once -
tx0/cpp:smart-pointer-get-testedallA smart pointer is tested for null through
get(), where the smart pointer itself converts tobool -
tx0/cpp:static-in-anonymous-namespaceallA declaration in an unnamed namespace says
static, which the namespace already implies -
tx0/cpp:std-bindallA callable is built with
std::bind, where a lambda says the same more plainly -
tx0/cpp:stray-semicolonallA second semicolon after a statement makes an empty statement
-
tx0/cpp:todo-commentallA comment marks work left to do with
TODO,FIXMEorXXX -
tx0/cpp:typedef-declarationallA type alias is declared with
typedef, whereusingreads left to right and also works for templates -
tx0/cpp:virtual-with-overrideallA member function says both
virtualandoverrideorfinal, andvirtualadds nothing -
tx0/cpp:void-parameter-listallA parameter list is written
(void), which in C++ means the same as()