codeql-coding-standards icon indicating copy to clipboard operation
codeql-coding-standards copied to clipboard

`M0-2-1`: Consider array copies with overlapping data

Open lcartey opened this issue 2 years ago • 1 comments

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 
}

lcartey avatar Nov 03 '22 10:11 lcartey

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?

knewbury01 avatar Jun 18 '24 22:06 knewbury01