github/codeql-coding-standards

`RULE-8-13`: Different compilations of the same variable

lcartey opened this issue · 0 comments

Affected rules

  • RULE-8-13

Description

In cases where a piece of code is compiled multiple times in different contexts, a variable declaration may be written to in some contexts, but not others. In CodeQL, we store different copies of the Variable for the different contexts (so that they can be distinguished in our analysis). However, flagging one copy of a variable as missing const, when other copies cannot be marked as const, seems unreasonable.

Example

int test(int* x) { // COMPLIANT - written to in at least one context
#ifdef FOO
  x = 1;
#endif
  return x;
}