codeql-coding-standards
codeql-coding-standards copied to clipboard
`M0-2-1`: Consider array copies with overlapping data
Affected rules
-
M0-2-1
Description
The query as currently written only considers overlapping as caused by unions. We should also consider whether overlapping arrays are covered by the same rule.
Example
#include <cstring>
int16_t a[20];
void f2(void) {
std::memcpy(&a[0], &a[1], 10u * sizeof(a[0])); // Non-compliant
std::memmove(&a[0], &a[1], 10u * sizeof(a[0])); // Compliant
std::memcpy(&a[1], &a[0], 10u * sizeof(a[0])); // Non-compliant
std::memmove(&a[1], &a[0], 10u * sizeof(a[0])); // Compliant
}
is this suggestion actually about checking for UB in some set of pointer handling functions? (like how use of overlapping objects in memcpy is UB?)
perhaps one way forward is to look for cases in a list of functions that would have restrict qualified pointers in c?