This repository is C++17/20 built with CMake, using the standard library and RAII for resource management. Review .cpp, .cc, .h, .hpp and CMakeLists.txt changes according to the rules below.
- A write past the end of a buffer is CRITICAL:
strcpy,strcat,sprintf,gets,memcpyorstd::copyinto a fixed-size buffer without a checked length, or indexing an array,std::vectoror pointer with a value from input that is not bounds-checked. - Use after free or a dangling reference is CRITICAL: returning a pointer, reference,
std::string_vieworstd::spanto a local or a temporary; keeping one to a container element across an operation that can reallocate; using an object afterdeleteor afterstd::move. - Iterator, pointer or reference invalidation is CRITICAL:
push_back,insert,eraseorresizeon a container while iterating it or holding iterators into it, without using the returned iterator. - Double
delete, mismatchednew[]/delete, orfreeon memory fromnewis CRITICAL. - Size arithmetic that can overflow before an allocation or a copy (
count * sizeof(T),len + 1on input sizes) is CRITICAL. - Reading an uninitialised variable or member is WARNING.
- A format string that comes from input (
printf(msg),syslog(prio, msg)) is CRITICAL. - Input passed to
system,popenor a shell is CRITICAL. - A file path from input without checking it stays under the intended root is CRITICAL.
- Owning raw pointers with manual
new/deletein new code are WARNING; usestd::unique_ptr,std::make_uniqueor a container. - A class that owns a resource without following the rule of zero, three or five (a destructor without matching copy and move handling) is WARNING.
- A base class with virtual functions and a public non-virtual destructor that is deleted through a base pointer is WARNING.
- Throwing from a destructor is WARNING.
- Data shared between threads and written by at least one, without a mutex, atomic or other synchronisation, is WARNING (data race, undefined behaviour).
- Calling
lock()/unlock()by hand instead ofstd::lock_guard,std::scoped_lockorstd::unique_lockis WARNING: an exception leaves the mutex locked. - A
std::threadthat can be destroyed while joinable (not joined or detached on every path) is WARNING: it callsstd::terminate. Preferstd::jthread. - Locking two mutexes in different orders in different places is WARNING (deadlock).
- Comparing signed and unsigned values in a loop condition or size check, or narrowing a
size_tintoint, is WARNING when the value can exceed the smaller range. - Ignoring the result of a function that reports failure by return value (an error code,
[[nodiscard]],std::optional, aboolfrom a write) is WARNING. reinterpret_castor a C-style cast for type punning is WARNING (undefined behaviour); usestd::bit_castormemcpy.- Catching exceptions by value is SUGGESTION; catch by
const&. - A move constructor or move assignment without
noexceptis SUGGESTION.
Formatting and lint are enforced by clang-format and clang-tidy, and the build runs with warnings as errors; do not comment on what they report. Prefer the patterns already used in the surrounding code over generic preferences.